【发布时间】:2025-12-30 12:55:11
【问题描述】:
我想使用 Excel 宏启动 Python 脚本以在后台运行。
我必须能够指定它使用系统 PATH(我不想假设 python 安装在哪里)以及一个特定的工作目录,它会在其中找到它需要的其他文件。
目前我使用以下,但这会阻止 Excel 进程,直到它完成。
Sub RunPython()
shellScript = "python Daily.py"
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
wsh.CurrentDirectory = Application.ThisWorkbook.Path
Set wshSystemEnv = wsh.Environment("Process")
Set WshShellExec = wsh.exec(shellScript)
Range("C7").Value = WshShellExec.StdErr.ReadAll ' Show error, if any
End Sub
如何在后台进程中运行它?
如果有方法在进程完成后调用另一个 VBA 子例程,则加分!
【问题讨论】:
-
您能否运行多个 Excel 实例,以便“释放”一个?
-
@QHarr – 是的,already found a way to do that by default!