0

Whenever I execute

xl = win32com.client.DispatchEx("Excel.Application")
xl.Visible = True

together, I get an error. But the error doesn't appear if I execute line by line

xl = win32com.client.DispatchEx("Excel.Application")

then

xl.Visible = True

Error:

xl = win32com.client.DispatchEx("Excel.Application")
xl.Visible = True
Traceback (most recent call last):

  File "<ipython-input-10-ea9dc88dd3f0>", line 2, in <module>
    xl.Visible = True

  File "C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 565, in __setattr__
    self._oleobj_.Invoke(entry.dispid, 0, invoke_type, 0, value)

com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2146777998), None)

Does anyone know how to fix this problem?

Joe Chan
  • 133
  • 3
  • 11

1 Answers1

0

win32com is poorly documented, so I wouldn't put it past them to have a few bugs, too.

I just checked, because I have a script that uses win32com as well, and I cannot reproduce your issue, but my Dispatch is different:

xl = win32com.client.gencache.EnsureDispatch('Excel.Application')

Maybe give that a try. Not sure what the differences are exactly. Are you Py2 or 3?

tst
  • 371
  • 1
  • 11