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?
- What have you tried so far?Charles Landau– Charles Landau2019-03-02 16:52:06 +00:00CommentedMar 2, 2019 at 16:52
1 Answer1
Have a look atxlwings. 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 usespsutil andappscript behind the scenes to communicate with the excel application.
Thexlwings documentation gives the following example for executing an excel VBA macro from python code:
Examples
This VBA function:
Function MySum(x, y) MySum = x + yEnd Functioncan be accessed like this:
>>> import xlwings as xw>>> wb = xw.books.active>>> my_sum = wb.macro('MySum')>>> my_sum(1, 2)3
Comments
Explore related questions
See similar questions with these tags.

