2010-02-18 188 views

回答

2

這說明要調用一個exe文件,並使用shell命令參數傳遞給它的場景。

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 
:下面的代碼通過傳遞URL作爲參數,檢查其中的chrome.exe居住,並呼籲www.google.com,從那裏的文件夾(假設你安裝了Chrome)