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 shell()
command.
How do I have to format the file path to tell Shell()
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)
shell(file)
file2 = "C:\Program Files\Test\foobar.exe /G" <---file never found
shell(file2)
I've succeeded with running other .exe's using shell() so I know it's not a problem with VBA or the function.
Example:
works = "C:\Program Files\Test\test.exe"
shell(works)
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 question is related to
excel
vba
shell
parameters
command-line-arguments
The below code will help you to auto open the .exe file from excel...
Sub Auto_Open()
Dim x As Variant
Dim Path As String
' Set the Path variable equal to the path of your program's installation
Path = "C:\Program Files\GameTop.com\Alien Shooter\game.exe"
x = Shell(Path, vbNormalFocus)
End Sub
Here are some examples of how to use Shell in VBA.
Open stackoverflow in Chrome.
Call Shell("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" & _
" -url" & " " & "www.stackoverflow.com",vbMaximizedFocus)
Open some text file.
Call Shell ("notepad C:\Users\user\Desktop\temp\TEST.txt")
Open some application.
Call Shell("C:\Temp\TestApplication.exe",vbNormalFocus)
Hope this helps!
Source: Stackoverflow.com