First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!

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 May 16 '14

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?

2 answers

Sort by » oldest newest most voted
1

answered May 19 '14

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")
link
0

answered May 19 '14

psseenmax gravatar image

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

link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.
Want to format code in your answer? Here is a one minute demo on Youtube

Add Answer

[hide preview]

Question Tools

Stats

Asked: May 16 '14

Seen: 1,832 times

Last updated: May 19 '14