运行 Python 来自 VBA 使用 xlwings 没有定义函数
Running Python from VBA using xlwings without defining function
我有 python 个程序使用 python 的 xlwings 模块与 excel 通信。它们工作得很好,但我想 运行 使用来自 excel 的按钮。我将 xlwings 导入到 VBA 并使用 RunPython 命令执行此操作。这也很好用,但是我使用 RunPython 的代码是这样的:
"from filename import function;function()"
这需要我将整个 python 程序变成一个函数。当我回去对 python 程序进行编辑时,这很烦人,因为每个变量都是本地变量。关于 运行从 RunPython 生成文件而无需从中创建函数的任何提示?
RunPython
基本上就是按照它所说的去做:运行 python 代码。因此,对于 运行 一个模块而不是单个函数,您可以这样做:RunPython("import filename")
。
我有 python 个程序使用 python 的 xlwings 模块与 excel 通信。它们工作得很好,但我想 运行 使用来自 excel 的按钮。我将 xlwings 导入到 VBA 并使用 RunPython 命令执行此操作。这也很好用,但是我使用 RunPython 的代码是这样的:
"from filename import function;function()"
这需要我将整个 python 程序变成一个函数。当我回去对 python 程序进行编辑时,这很烦人,因为每个变量都是本地变量。关于 运行从 RunPython 生成文件而无需从中创建函数的任何提示?
RunPython
基本上就是按照它所说的去做:运行 python 代码。因此,对于 运行 一个模块而不是单个函数,您可以这样做:RunPython("import filename")
。