Austin A Austin A - 5 months ago 89x
Bash Question

How do you run a .exe with parameters using vba's shell()?

I have a target file path that is structured like example below.

C:\Program Files\Test\foobar.exe /G

What I need to do is be able to execute this file using vba's

How do I have to format the file path to tell
that there is an argument that it needs to call along with running the .exe

What I've read/tried (with no avail) is below with the results to the right.

file = """C:\Program Files\Test\foobar.exe"" /G" <---Bad file name or number (Error 52)

file2 = "C:\Program Files\Test\foobar.exe /G" <---file never found

I've succeeded with running other .exe's using shell() so I know it's not a problem with vba or the function.


works = "C:\Program Files\Test\test.exe"

I'm not particularly familiar with the process involved with executing files that require additional parameters so if I misspeak or you need more information, please let me know.


This works for me (Excel 2013):

Public Sub StartExeWithArgument()
    Dim strProgramName As String
    Dim strArgument As String

    strProgramName = "C:\Program Files\Test\foobar.exe"
    strArgument = "/G"

    Call Shell("""" & strProgramName & """ """ & strArgument & """", vbNormalFocus)
End Sub

With inspiration from here