Call Shell with Parameter

tho28199

Registered User.
Local time
Today, 02:49
Joined
Jan 25, 2007
Messages
28
Hi all,

Can anyone please help me out with the correct syntax for this:

Dim stAppName As String
stAppName = "C:\Program Files\Gavlock Consulting\SmartDir.exe" /run "C:\Reports\WeeklyFL.ini"
Call Shell(stAppName, vbHide)

I have tried searching the forum, but obviously haven't found the correct search keywords...

VBA apparently doesn't like the /run parameter.

Stu
 
The problem here is that you need a double quote to appear within a string that is itself delimited by double quotes. One solution is to put two double quotes in a row, like this...
Code:
stAppName = "C:\Program Files\SmartDir.exe"" /run ""C:\Reports\WeeklyFL.ini"
...and VBA will interpret that as a single string expression.
You can also produce a double quote character using chr(34) ...
Code:
debug.print chr(34)
Cheers,
 
Thanks, lagbolt. The double-quotes are now accepted by VBA, but I am now getting a Run-time error '53' File not found.

However, I tried using Windows > Run with the following, and it worked perfectly:
"C:\Program Files\Gavlock Consulting\SmartDir.exe" /run "C:\DataEntry.ini"

Any ideas on why the Call Shell can't find the file?
 
Code:
stAppName = """C:\Program Files\Gavlock Consulting\SmartDir.exe"" /run ""C:\Reports\WeeklyFL.ini"""
 
Thanks, George... the quotes enclosing the whole thing did the trick.

I love this forum...
 
My error. Thanks George. Cheers tho.
 
Thanks for your help ... my code is shown below for running Notepad++ with commandline options/arguments from Access VBA.

strNPPathFilename = "C:\Program Files\Notepad++\notepad++.exe"
strNPCmdLineOption1 = "-ro"
strNPCmdLineOption2 = "-nosession"
strTxtPathFilename = strTxtPath & strTxtFilename

' display results in Notepad ++ using commandline options
varID = Shell(Chr$(34) & strNPPathFilename & Chr$(34) & Chr$(32) & _
Chr$(34) & strNPCmdLineOption1 & Chr$(34) & Chr$(32) & _
Chr$(34) & strNPCmdLineOption2 & Chr$(34) & Chr$(32) & _
Chr$(34) & strTxtPathFilename & Chr$(34), vbNormalFocus)
'

Interestingly :(, I needed to separate the 2 commandline options to get them to work properly.

Again, thanks :) for your help with this issue.

Charles.
 

Users who are viewing this thread

Back
Top Bottom