使用 VBA 从 Excel 运行 bat 文件

4es*_*est 3 excel vba batch-file batch-processing

我有test.bat文件包含脚本:

copy host_name table_name -p table_name -t "file.csv"
Run Code Online (Sandbox Code Playgroud)

通常当我点击它时,它工作正常。现在,我想使用 vba 从 Excel 运行 test.bat 文件。

strPath = ws1.Range("G2").value & "\" 'Directory to folder with bat
Shell strPath & "\test.bat", vbNormalFocus
Run Code Online (Sandbox Code Playgroud)

出了点问题,因为我只看到快照/剪辑:就像打开和关闭一秒钟一样......

4es*_*est 5

刚刚解决了:

ChDir ThisWorkbook.Path & "\folder\"
Shell ThisWorkbook.Path & "\folder\test.bat", vbNormalFocus
Run Code Online (Sandbox Code Playgroud)