如何将VBA输出发送到Python脚本?

2024-09-27 21:25:59 发布

您现在位置:Python中文网/ 问答频道 /正文

下面是一个代码片段:

' Send the query in the body to Jira, and get the response from Jira

strJsonResponse = Utilities.JiraRequest(strJQLQuery)

我希望将这个json放到Python解析器中,然后将解析后的json返回到电子表格中。这可能吗?我以前从没和VBA合作过。在

我已经下载了jiraapi模块和openpyxl模块。在


Tags: 模块andtheto代码infromsend
2条回答

您可以创建一个新的文本文件并将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解析文件。也许有更好的办法,但我不确定是什么。在

我认为TechScript提出了一个合理的问题。您确定除了Python代码之外还需要使用VBA代码吗?通过运行使用openpyxl模块的Python代码,您可以读取和修改Excel文件中的所有内容,完全不需要运行Excel应用程序。在

有时候将VBA和Python代码耦合是有原因的。最常见的一种情况是,您希望使用Excel作为熟悉的图形用户界面来指导数据操作操作,但希望Python完成实际的繁重工作。如果您希望这样做,那么有一个xlwings模块。Xlwings使call Python code from inside VBA modules, and to exchange data values between VBA and Python变得容易。在

相关问题 更多 >

    热门问题