win32 com problem

Discussion in 'Python' started by Mike P, Dec 5, 2006.

  1. Mike P

    Mike P Guest

    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?
     
    Mike P, Dec 5, 2006
    #1
    1. Advertisements

  2. Mike P

    John Machin Guest

    Does it? All I see is a message that it can't find a macro.
    What happens when you run the macro from the Excel UI?

    Have you tried using makepy?
    ??? It might help if you showed us the code that you are executing.
     
    John Machin, Dec 5, 2006
    #2
    1. Advertisements

  3. Mike P

    Mike P Guest

    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
     
    Mike P, Dec 5, 2006
    #3
  4. Mike P

    John Machin Guest

    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"?
    See above questions.
    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
     
    John Machin, Dec 5, 2006
    #4
  5. Mike P

    Mike P Guest

    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
     
    Mike P, Dec 5, 2006
    #5
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.