James Carter
James Carter

Reputation: 833

Running Python from VBA using xlwings without defining function

I have python programs that use python's xlwings module to communicate with excel. They work great, but I would like to run them using a button from excel. I imported xlwings to VBA and use the RunPython command to do so. That also works great, however the code I use with RunPython is something like:

"from filename import function;function()"

which requires me to make the entire python program a function. This is annoying when I go back to make edits to the python program because every variable is local. Any tips on running the file from RunPython without having to create a function out of it?

Upvotes: 0

Views: 1064

Answers (1)

Felix Zumstein
Felix Zumstein

Reputation: 7070

RunPython basically just does what it says: run python code. So to run a module rather than a single function, you could do: RunPython("import filename").

Upvotes: 3

Related Questions