有没有办法在Excel-VBA中调用python代码? [英] Is there a way to call a python code in Excel-VBA?

查看:303
本文介绍了有没有办法在Excel-VBA中调用python代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含宏的excel文件(Main.xlsm)。我有一个python文件(python.py)来生成一个辅助Excel文件(sub.xlsx),我将进一步调用Main.xlsm文件的宏。这个由python.py运行生成的sub.xlsx文件保存在同一个工作目录中。



现在我想让这个python.py在Main.xlsm宏的运行期间执行,然后使用这个xlsx文件。我基本上想减少外部执行python.py的步骤。有没有命令呢?我是VBA的新手。

解决方案

最简单的方法是运行python解释器与 Shell 命令

  Shell(python.exe&&& arguments)


I have an excel file(Main.xlsm) containing macros. I have a python file(python.py) to generate a subsidiary excel file(sub.xlsx) which i would further call in the macros of Main.xlsm file. This sub.xlsx file which is generated by the run of python.py is saved in the same working directory.

Now I want to make this python.py to be executed during the run of the Main.xlsm macros and then use this xlsx file. I basically want to reduce the step of executing python.py externally. Is there a command for that? I am new to VBA.

解决方案

The simplest way is to run the python interpreter with the Shell command

Shell ("python.exe " & yourScript & " " & arguments)

这篇关于有没有办法在Excel-VBA中调用python代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆