gpt4 book ai didi

python - 从 VBA 调用 python 脚本

转载 作者:太空宇宙 更新时间:2023-11-04 05:01:59 24 4
gpt4 key购买 nike

似乎有很多关于这个的线程,它们都指向这个解决方案:

Function call_py()

Dim rv As Variant
Const pypath = "C:\Users\user\AppData\Local\Programs\Python\Python36-32\python.exe "
Const scriptpath = "c:\Users\user\Desktop\test.py"

rv = Shell(pypath & scriptpath, vbNormalFocus)


End Function

或类似的东西。不过,所有这一切都是在不执行脚本的情况下使 shell 弹出和消失。我做错了什么?

P.

最佳答案

试试这个:

Sub bat()
Dim batch, fso As Object
Dim path As String
path = "c:\Users\user\Desktop\"

Set fso = CreateObject("Scripting.FileSystemObject")
Set batch = fso.CreateTextFile(path & "python.bat", True)
batch.writeline "cd " & path
batch.writeline "python test.py"
batch.Close

Shell path & "python.bat", 1
End Sub

关于python - 从 VBA 调用 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45489577/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com