我有一个目标文件路径,结构如下所示。
C:\Program Files\Test\foobar.exe /G
我需要做的是能够使用VBA的shell()
命令执行这个文件。
如何格式化文件路径,以便告诉Shell()
在运行.exe时需要调用一个参数
我读过的/尝试过的(没有结果)在下面给出了正确的结果。
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)
我已经成功地使用shell()运行了其他..exe,所以我知道这不是VBA或函数的问题。
示例:
works = "C:\Program Files\Test\test.exe"
shell(works)
我对执行需要额外参数的文件的过程并不特别熟悉,所以如果我说错了或者您需要更多的信息,请告诉我。
发布于 2014-06-10 14:25:42
这适用于我(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
来自这里的灵感,https://stackoverflow.com/a/3448682。
发布于 2014-04-04 15:20:34
下面是如何在VBA中使用Shell的一些示例。
在Chrome中打开堆栈溢出。
Call Shell("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" & _
" -url" & " " & "www.stackoverflow.com",vbMaximizedFocus)
打开一些文本文件。
Call Shell ("notepad C:\Users\user\Desktop\temp\TEST.txt")
打开一些应用程序。
Call Shell("C:\Temp\TestApplication.exe",vbNormalFocus)
希望这能有所帮助!
发布于 2016-08-22 13:16:01
下面的代码将帮助您自动打开excel中的.exe文件.
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
https://stackoverflow.com/questions/20917355
复制相似问题