我想使用Visual Basic for Applications执行如下所示的shell命令。
C:\Temp\gc.exe 1
我该怎么做?
答案 0 :(得分:11)
答案 1 :(得分:2)
这显示了您想要调用exe文件并使用shell命令将参数传递给它的方案。以下代码通过传递url作为参数来检查chrome.exe驻留和调用www.google.com的文件夹(假设您安装了chrome):
Public Sub Display_Google()
Dim chromePath As String
chromePath = "C:\Program Files\Google\Chrome\Application\chrome.exe"
If FileExists(chromePath) Then
Shell (chromePath & " -url" & " " & "www.google.com"), vbMaximizedFocus
Else
chromePath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
Shell (chromePath & " -url" & " " & "www.google.com"), vbMaximizedFocus
End If
End Sub
Public Function FileExists(ByVal FileName As String) As Boolean
On Error Resume Next
FileExists = Not CBool(GetAttr(FileName) And (vbDirectory Or vbVolume))
On Error GoTo 0
End Function