1

I have run the Export to Excel and created a macro in a workbook. How can I call this macro using Python?

I have run the Export to Excel and created a macro in a workbook. How can I call this macro using Python?

anonymous user
asked 2014-05-15 23:09:27 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

2 Answers

1

I've done this a few times actually. What I end up doing is closing the file via excelPy, and then reopening it with win32com, and running the macro there. Assuming your macro name is "MacroName", your excel file is "xlsfile" and it is located at "THISFOLDER":

# Close excel file
testxls = excelpy.workbook(xlsfile)
testxls.close()

# Open excel file via win32com
import win32com.client as win32
xl = win32.Dispatch('Excel.Application')
xl.Visible = True
ss = xl.Workbooks.Open(THISFOLDER + "\\" + xlsfile)
xl.Run("MacroName")
Eli Pack's avatar
823
Eli Pack
answered 2014-05-18 23:13:00 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
0

Thats awesome and it worked! Thanks...the more I can automate my daily processes the better.

psseenmax's avatar
1
psseenmax
answered 2014-05-19 16:20:57 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments

Your Answer

Login/Signup to Answer