+ Reply to Thread
Results 1 to 5 of 5

Thread: Shell - trouble with variables and quotes

  1. #1
    Registered User
    Join Date
    07-14-2010
    Location
    Snowmass, Colorado
    MS-Off Ver
    Excel 2007
    Posts
    30

    Shell - trouble with variables and quotes

    Hello,

    I'm having trouble with the Shell command from VBA.

    This line of code works:

    RetVal = Shell("""C:\Program Files\eQUEST 3-64\eQuest.exe"" ""C:\Documents and Settings\All Users\Documents\eQUEST 3-64 Projects\Large Office Case Study 6\BatchData.eQBatch""", vbMaximizedFocus)
    But when I replace the hard coded paths with the variables, as below, it does not work and tells me "C:\Documents cannot be found" because I am not passing in any " around the parameters.

    RetVal = Shell(ProgFolder & "\eQuest.exe " & ProjFolder & "\BatchData.eQBatch", vbMaximizedFocus)
    How do I pass in quotes around the path and parameter, as I'm doing in the example above???

    Thanks!
    BRL
    Last edited by brl8; 09-30-2010 at 12:05 PM.

  2. #2
    Valued Forum Contributor MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    5,298

    Re: Shell - trouble with variables and quotes

    These quote problems are stumpers and I've spent lots of time building them incorrectly.

    I've found that building a String Variable first, with all the correct values and then placing this in the call normally works.

    My second hint on putting quotes in these calls is to defind a Constant called QUOTE = Chr(34) and use & QUOTE & in building your strings.

  3. #3
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: Shell - trouble with variables and quotes

    Double them as in your original:

    RetVal = Shell("""" & ProgFolder & "\eQuest.exe"" """ & ProjFolder & "\BatchData.eQBatch""", vbMaximizedFocus)

  4. #4
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Shell - trouble with variables and quotes

    This is the way I do it:

    RetVal = Shell(replace("#" & ProgFolder & "\eQuest.exe# #" & ProjFolder & "\BatchData.eQBatch#","#",chr(34)), vbMaximizedFocus)



  5. #5
    Registered User
    Join Date
    07-14-2010
    Location
    Snowmass, Colorado
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Shell - trouble with variables and quotes

    Awesome! Thanks all for the great suggestions.

    Here's what it took:

    Quote = Chr(34)
    ShellStr = Quote & ProgFolder & "\eQuest.exe" & Quote & " " & Quote & ProjFolder & "\BatchData.eQBatch" & Quote      
    RetVal = Shell(ShellStr, vbMaximizedFocus)
    Thanks All.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0