Voglio eseguire un comando di shell come il seguente utilizzando Visual Basic, Applications Edition.Come posso eseguire un comando shell usando VBA?
C:\Temp\gc.exe 1
Come posso farlo?
Voglio eseguire un comando di shell come il seguente utilizzando Visual Basic, Applications Edition.Come posso eseguire un comando shell usando VBA?
C:\Temp\gc.exe 1
Come posso farlo?
Questo mostra gli scenari in cui si desidera chiamare un file exe e passare un argomento ad esso utilizzando il comando di shell. Il seguente codice controlla la cartella in cui risiedono chrome.exe e chiamando www.google.com, da lì (supponendo che si è installato Chrome) passando come argomento url:
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