Ausführen einer BAT-Windows-Batchdatei von Excel VBA

4521
Vincent Tang

Ich habe eine Datei mit dem Namen newcurl.batinnerhalb des aktuellen Verzeichnisses, in dem sich meine Excel-Datei befindet

Ich möchte, dass ExcelVBA diese Datei ausführt

Ich habe es versucht:

Shell "cmd.exe /k ""cd " & """ & ThisWorkbook.path & """ & " newcurl.bat"""

aber es ist nur CD's zum aktuellen Ordnerpfad, führt aber die newcurl.batDatei nicht physisch aus

2

2 Antworten auf die Frage

1
Vincent Tang

Ich habe es herausgefunden.

Ich hatte ein personal.xlsb-Makrobook und thisworkbook.pathverwies auf die falsche Arbeitsmappe.

Am Ende habe ich das getan:

Dim folderPath As String Dim shellCommand As String  folderPath = Application.ActiveWorkbook.Path shellCommand = """" & folderPath & "\" & "newcurl.bat" & """" Call Shell(shellCommand, vbNormalFocus) 
0
Leviathan

Sie haben die doppelten Anführungszeichen durcheinander gebracht - ThisWorkbook.pathwird im Befehl wörtlich verwendet.

Sie können es selbst sehen, wenn Sie den Befehl an die Konsole ausgeben:

Dim strCommand As String strCommand = "cmd.exe /k ""cd " & """ & ThisWorkbook.path & """ & " newcurl.bat""" Debug.Print strCommand Shell strCommand 
Am Ende habe ich etwas anderes in dem Kommentar gemacht, der für mich funktioniert hat. Vincent Tang vor 6 Jahren 0