faqts : Computers : Programming : Languages : Python : Platforms : Windows

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 11 people (64%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

Can I execute an Excel macro from Python and then return control to Python ?

Jul 29th, 2006 17:04
Mustafa Görmezer, Jim McIlroy, Howto run a Macro in Office from Python


You can do it by using the method run(). For example:

import win32com.client
app = win32com.client.Dispatch('Excel.Application')
wb=app.Workbooks.Open('c:\\test.xls')
wb.Application.Run("MYCUSTOM.XLM!My_Function", 1, 5)

The Macro is stored in a macro template file mycustom.xlm. You can also
use the macro name if it is in the excel workbook. The numbers 1 and 5
are arguments which are passed to the function My_Function.

More information can be found in the ms visual basic online help or msdn.

Mustafa Görmezer
http://www.goermezer.de