我在 Excel 中从 vba 调用 python 脚本时遇到问题。我阅读了解决相同问题的其他线程,但是当我运行代码时,Python 屏幕闪烁,然后消失。仅供参考,我下载了适用于 Windows 10 的 python 3.6.5 并将其添加到 PATH 中。有人可以告诉我为什么屏幕闪烁以及我能做些什么来解决它吗?谢谢
Sub Run_python()
Dim Ret_Val
Dim args As String
args = "C:\Users\opera\AppData\Local\Programs\Python\Python36\Tools\scripts\db2pickle.py"
Ret_Val = Shell("C:\Users\opera\AppData\Local\Programs\Python\Python36\python.exe" & " " & args, vbNormalFocus)
If Ret_Val = 0 Then
MsgBox "Couldn't run python script!", vbOKOnly
End If
End Sub
屏幕闪烁并快速返回,因为程序失败或运行得太快完成
您是否尝试过从命令行运行它来看看发生了什么?
如果运行正常,您可以强制命令窗口保持打开状态,以便您可以从 Shell 命令中读取使用 python 时发生的情况
Call Shell("cmd.exe /S /K" & "C:\Users\opera\AppData\Local\Programs\Python\Python36\python.exe" & " " & args, vbNormalFocus)
/S Modifies the treatment of string after /C or /K
/C Carries out the command specified by string and then terminates
/K Carries out the command specified by string but remains
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)