Ask Your Question
1

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

asked 2014-05-15 23:09:27 -0500

anonymous user

Anonymous

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

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2014-05-18 23:13:00 -0500

Eli Pack gravatar image

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")
edit flag offensive delete link more
0

answered 2014-05-19 16:20:57 -0500

psseenmax gravatar image

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

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

Stats

Asked: 2014-05-15 23:09:27 -0500

Seen: 1,819 times

Last updated: May 19 '14