【发布时间】:2013-05-07 09:09:19
【问题描述】:
我通过 VBA 宏启动 Python。如果 Python 路径不好,我想要一个正确的错误消息。 我在 2 台不同的计算机上使用此宏,而这 2 台计算机上的 Python 路径并不相同。 2 条路径位于 2 个不同的单元格名称 path_Python 和 path_Python_2 这是我的代码:
Function launchPython() As Boolean
Dim pathScript As String
pathScript = [path_files] + "code.py"
On Error GoTo err
Shell [path_Python].Value & " " & pathScript
launchPython = True
Exit Function
err:
On Error GoTo err2
Shell [path_Python_2].Value & " " & pathScript
launchPython = True
err2:
launchPython = False
MsgBox "Error: please check Python paths"
End Function
问题是,当 2 条路径不好时,我没有进入 err2,而是在
上阻止了 VBA 错误消息err:
On Error GoTo err2
Shell [path_Python_2].Value & " " & pathScript
我该如何解决这个问题? 非常感谢
【问题讨论】:
-
您不能使用
IF语句而不是处理程序来验证路径吗?
标签: vba error-handling