如何将 VBA 输出发送到 Python 脚本?
How do I send VBA output to a Python script?
这是一个代码片段:
' Send the query in the body to Jira, and get the response from Jira
strJsonResponse = Utilities.JiraRequest(strJQLQuery)
我想将此 json 放入 Python 解析器,然后 return 将已解析的 json 放回电子表格中。这可能吗?我以前从未与 VBA 合作过。
我已经下载了 JIRA API 模块和 openpyxl 模块。
您可以创建一个新的文本文件并向其中输出 VBA
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Fileout As Object
Set Fileout = fso.CreateTextFile("C:\your_path\vba.txt", True, True)
Fileout.Write strJsonResponse
Fileout.Close
VBA code found here
然后让 VBA 启动你的 python 脚本,你可以让 python 解析你的文件。可能有更好的方法可以做到这一点,但我不确定是什么。
我认为 Tehscript 提出了一个有效的问题。您确定除了 Python 代码之外还需要使用 VBA 代码吗?通过 运行ning Python 使用 openpyxl 模块的代码,您基本上可以读取和修改 Excel 文件中的所有内容,完全不需要 运行 一个 Excel 申请。
有时耦合 VBA 和 Python 代码是有正当理由的。最常见的一种情况是当您想使用 Excel 作为熟悉的图形用户界面来指导数据操作时,但又希望 Python 来完成实际的繁重工作。如果您想这样做,那么 xlwings module. Xlwings makes it easy to call Python code from inside VBA modules, and to exchange data values between VBA and Python.
这是一个代码片段:
' Send the query in the body to Jira, and get the response from Jira
strJsonResponse = Utilities.JiraRequest(strJQLQuery)
我想将此 json 放入 Python 解析器,然后 return 将已解析的 json 放回电子表格中。这可能吗?我以前从未与 VBA 合作过。
我已经下载了 JIRA API 模块和 openpyxl 模块。
您可以创建一个新的文本文件并向其中输出 VBA
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Fileout As Object
Set Fileout = fso.CreateTextFile("C:\your_path\vba.txt", True, True)
Fileout.Write strJsonResponse
Fileout.Close
VBA code found here
然后让 VBA 启动你的 python 脚本,你可以让 python 解析你的文件。可能有更好的方法可以做到这一点,但我不确定是什么。
我认为 Tehscript 提出了一个有效的问题。您确定除了 Python 代码之外还需要使用 VBA 代码吗?通过 运行ning Python 使用 openpyxl 模块的代码,您基本上可以读取和修改 Excel 文件中的所有内容,完全不需要 运行 一个 Excel 申请。
有时耦合 VBA 和 Python 代码是有正当理由的。最常见的一种情况是当您想使用 Excel 作为熟悉的图形用户界面来指导数据操作时,但又希望 Python 来完成实际的繁重工作。如果您想这样做,那么 xlwings module. Xlwings makes it easy to call Python code from inside VBA modules, and to exchange data values between VBA and Python.