社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  PCG  »  全部回复
回复总数  1
3 年前
回复了 PCG 创建的主题 » 为什么VB外壳函数不停止Python代码执行窗口?

该问题与路径中的空间有关。python路径中的空格可以,但是python脚本路径不应该有任何空格。当有空格时,它会被分解成单独的变量,并且永远不会将脚本视为文件。因此,解决方法是对带有空格的路径使用双引号。

VB脚本应如下所示:

Sub run_python()

python_exe = "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python.exe"
python_script = "C:/Users/Goerge/OneDrive - MS Corporation/Documents/Development/python-excel/excel_python.py"

If Dir(python_exe) = "" Then
    MsgBox ("Python executabl does not exists")
End If

If Dir(python_script) = "" Then
    MsgBox ("Python script does not exists")
End If

python_code = python_exe & " " & """" & python_script & """"
MsgBox python_code
RetVal = Shell(python_code)

'Shell "pskill " & " " & RetVal

End Sub