【问题标题】:Run a python code (Anaconda3) using a VBA button in the Excel input workbook使用 Excel 输入工作簿中的 VBA 按钮运行 python 代码 (Anaconda3)
【发布时间】:2021-10-24 18:27:23
【问题描述】:

我编写了一个 Python 代码,它使用 Excel 工作簿中的输入数据执行一些计算。 我的目标是在自动运行 python 脚本的输入 excel 工作簿中添加一个按钮。 我已经添加了与以下宏相关联的按钮:

'''

Sub RunPythonScript()

    Dim objShel As Object
    Dim PythonExe, PythonScript As String
    
    Set objShell = VBA.CreateObject("Wscript.Shell")
    
    PythonExe = "*path to python.exe*"
    
    PythonScript = """*path to the code*"""
    
    objShell.Run PythonExe & PythonScript

End Sub

'''

宏不工作并返回错误Method 'Run' of object IWshShell3 failed! 我不知道问题是否是由于我打开了 python 代码的输入 excel 工作簿(通常应该关闭以使代码工作)。

【问题讨论】:

标签: python excel vba anaconda


【解决方案1】:

也许您可以尝试将运行 python 命令放入 bat 文件中,然后运行该 bat 文件

【讨论】:

  • 我能够克服错误消息,但是现在当我运行 VBA 代码时没有任何反应!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多