VBA shell函数无法运行.bat作业

时间:2015-02-05 17:27:26

标签: vba batch-file

我的shell函数没有启动.bat作业。有人可以帮忙吗?

Public Sub TESTRUN()
Dim Command As String
Dim pathcrnt As String
Dim RetVal

pathcrnt = ActiveWorkbook.path
Command = "RunMGALFA -ain:" & Range("AinFile") & " -val:" & Range("ValDate") & " -run:" & Range("RunNumber")

Open pathcrnt & "\test.bat" For Output As #1
Print #1, Command
Close #1
Shell pathcrnt & "\test.bat", vbMaximizedFocus

End Sub

1 个答案:

答案 0 :(得分:1)

除非RunMGALFApathcrnt位于同一目录或系统%PATH%变量中注册的位置,否则您的脚本将无效。

我建议在生成的脚本中提供RunMGALFA的完整路径:

Command = "C:\Path\To\RunMGALFA -ain:" & Range("AinFile") & " -val:" & Range("ValDate") & " -run:" & Range("RunNumber")