[Tutor] run excel macro from python

Pirritano, Matthew MPirritano at ochca.com
Tue Nov 15 17:07:55 CET 2011


Pythonistas,

 

I am running an excel macro from python with the following code:

 

The problem I'm having is that when I try to run this function I get a
dialog window that pops up titled: "Update Values: Personal.xls" When I
try to cancel out of it I get directed to a type mismatch in the excel
macro.

 

The program is very long so I won't paste the whole thing here, just the
call to the excel macro. What seems key is that the macro runs fine in
excel. And I've run excel macros from python before. The only difference
is that now the macro also calls some excel user defined functions.
Since they live in Personal.xls I'm thinking that is the wrinkle here.
All of my searching has led me nowhere. Has no one ever had this issue?

 

You'll note the excessive closing language in the function. I thought
that maybe what was happening is that more than one instance of excel
was open and that was causing a problem with accessing personal.xls, as
will happen if you try to manually open more than one instance of excel
in windows.

 

def runExcelMacro():

    excel = win32.Dispatch("Excel.Application")

    excel.Visible = 0

    fTest =
excel.Workbooks.Add("D:\\Data\\Excel\\Blank_Summary_Report_Template_Macr
o_20111114.xls")

    macName = "macroAllFiles"

    macName = fTest.Name + '!' + macName

    print macName

    excel.Run(macName)

    excel.DisplayAlerts = 0

    fTest.Close(1)

    excel.Quit()

    del excel

 

Any ideas!?

 

Thanks

Matt

 

Matthew Pirritano, Ph.D.

Research Analyst IV

Medical Services Initiative (MSI)

Orange County Health Care Agency

(714) 568-5648

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111115/adc5a434/attachment-0001.html>


More information about the Tutor mailing list