Skip to content Skip to sidebar Skip to footer

Pyvot: Can I Run Excel VBA Macros From Python Script?

Say I have loaded Report WW26blueprint_with_chart_330.xlsm in the report object with the following code (the print.range is used here to test that the workbook is loaded): import

Solution 1:

This did it for me:

report.xlWorkbook.Application.Run('Macro1')

Solution 2:

Didn't manage to do it with pyvot but can be done using pywin32 as following:

import win32com.client
xl=win32com.client.Dispatch("Excel.Application")
xl.Workbooks.Open(Filename="C:\Users\florinescu_eduard\Downloads\\Report WW26blueprint_with_chart_330.xlsm",ReadOnly=1)
xl.Application.Run("Macro1")
xl.Workbooks(1).Close(SaveChanges=1)
xl.Application.Quit()
xl=0

Solution 3:

It's very important to make sure xl.Application.Quit() while you are debug. Other than you might get confused.


Post a Comment for "Pyvot: Can I Run Excel VBA Macros From Python Script?"