且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Shell函数运行exe时找不到文件错误

更新时间:2023-11-15 20:37:46

ChDir 只能将当前目录更改为同一个驱动器上的另一个目录 - 如果要切换,您需要首先使用 ChDrive 到不同驱动器上的文件夹。

ChDir will only work to change the current directory to another on the same drive - you need to use ChDrive first if you want to switch to a folder on a different drive.

更好的是,将完整路径传递给Shell,并跳过更改当前目录。

Better yet, pass the full path to Shell and skip changing the current directory.

Sub RunProcessor()
    If MsgBox("Run simulation?", vbYesNo) = vbYes Then
        Shell (ThisWorkbook.Path & "\runsims.exe")
    End If
End Sub