1

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?

askedMar 2, 2019 at 16:15
Mikael Molet's user avatar
1
  • What have you tried so far?CommentedMar 2, 2019 at 16:52

1 Answer1

5

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 Function

can be accessed like this:

>>> import xlwings as xw>>> wb = xw.books.active>>> my_sum = wb.macro('MySum')>>> my_sum(1, 2)3
answeredMar 2, 2019 at 17:03
Xukrao's user avatar
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.