win32 com problem

M

Mike P

I've got a slight problem when running an excel macro from python using
the win32.com.client module, in that it says it can't load the DLL file
(it doesn't say which one)

and gives me the following error message

Traceback (most recent call last):
File "<string>", line 93, in ?
File "<COMObject <unknown>>", line 14, in Run
File "C:\Python24\lib\site-packages\win32com\client\dynamic.py", line
258, in _ApplyTypes_
result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType,
argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0,
'Microsoft Office Excel', "The macro 'CTP.xla!sheet1.CTP' cannot be
found.", 'C:\\Program Files\\Microsoft
Office\\OFFICE11\\1033\\xlmain11.chm', 0, -2146827284), None)


Anybody have any ideas what this means?
 
J

John Machin

Mike said:
I've got a slight problem when running an excel macro from python using
the win32.com.client module, in that it says it can't load the DLL file

Does it? All I see is a message that it can't find a macro.
(it doesn't say which one)

What happens when you run the macro from the Excel UI?

Have you tried using makepy?
and gives me the following error message

Traceback (most recent call last):
File "<string>", line 93, in ?

??? It might help if you showed us the code that you are executing.
 
M

Mike P

Thanks for the quick reply,

the code i am running is the following

import win32com.client
xl = win32com.client.Dispatch("Excel.Application")
ppt = win32com.client.Dispatch("PowerPoint.Application")
ppt.Visible = 1 #open MS Powerpoint
xl.Visible = 1 #open MS Excel
xl.Workbooks.Open('%s/working_output.xls' % (working_dir))
xl.Workbooks.Open('Z:\\projects\\surveys\\SPSS - Generic
files\\CTP.xla')
ppt.Presentations.Open('Z:\\projects\\surveys\\SPSS - Generic
files\\Basic Template.ppt')
xl.Application.Workbooks("working_output").Activate
xl.Application.Run("CTP.xla!sheet1.CTP")

I'm running via SPSS V15 which has a python plugin, i was previousky
running in V14 using the exact same code with no problems?

Thanks again

Mike
 
J

John Machin

Mike said:
Thanks for the quick reply,

the code i am running is the following

import win32com.client
xl = win32com.client.Dispatch("Excel.Application")
ppt = win32com.client.Dispatch("PowerPoint.Application")
ppt.Visible = 1 #open MS Powerpoint
xl.Visible = 1 #open MS Excel
xl.Workbooks.Open('%s/working_output.xls' % (working_dir))
xl.Workbooks.Open('Z:\\projects\\surveys\\SPSS - Generic
files\\CTP.xla')

Does this file contain a sheet named "sheet1"? Maybe it should be
"Sheet1"; I can never remember what is case-sensitive and what's not
:)

If so, does that sheet contain a macro called "CTP"?
ppt.Presentations.Open('Z:\\projects\\surveys\\SPSS - Generic
files\\Basic Template.ppt')
xl.Application.Workbooks("working_output").Activate
xl.Application.Run("CTP.xla!sheet1.CTP")

See above questions.
I'm running via SPSS V15 which has a python plugin, i was previousky
running in V14 using the exact same code with no problems?

Have you asked SPSS about the CTP.xla file (which I guess is supplied
by them)?

Don't expect so fast a response this time -- it's sleep time in this
timezone :)

Cheers,
John
 
M

Mike P

No Problem,

Thanks for your help so far, i've sent this problem off to SPSS as it
seems it doesn't work on a work colleagues machine either

Thanks for your time though

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top