Reputation: 33
I was wondering whether it would be possible to run an excel macro via Python (using a Mac, I specify the machine because I know that most of the codes used win32., which is not for Mac users). Did someone try to figure it out?
Upvotes: 1
Views: 1946
Reputation: 8623
Have a look at xlwings
. It is a well thought out python package that allows you to control an excel application from python (and vice versa). It supports both Windows and Mac. On Mac it uses psutil
and appscript
behind the scenes to communicate with the excel application.
The xlwings documentation gives the following example for executing an excel VBA macro from python code:
Examples
This VBA function:
Function MySum(x, y) MySum = x + y End Function
can be accessed like this:
>>> import xlwings as xw >>> wb = xw.books.active >>> my_sum = wb.macro('MySum') >>> my_sum(1, 2) 3
Upvotes: 5