Execute .bat file from Excel VBA Macro

后端 未结 4 668
逝去的感伤
逝去的感伤 2020-12-18 05:14

Im having a problem with my excel vba macro. I need it to execute a batch file which is in the same folder as the excel workbook. The code works well sometimes. I don\'t kno

4条回答
  •  悲&欢浪女
    2020-12-18 05:41

    I'm pretty sure the problem is down to this line

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

    You need a space in front of the && to separate it from the cd command and after it to separate it from the code.bat.

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

提交回复
热议问题