【发布时间】:2011-01-18 10:07:49
【问题描述】:
我想使用 Visual Basic for Applications 执行如下 shell 命令。
C:\Temp\gc.exe 1
我该怎么做?
【问题讨论】:
我想使用 Visual Basic for Applications 执行如下 shell 命令。
C:\Temp\gc.exe 1
我该怎么做?
【问题讨论】:
【讨论】:
这显示了您要调用 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
【讨论】: