Hi,

I am trying to dipatch excel using the win32com library but for some reason
am running into an issue. I have the following code:


import win32com.clientimport os

file1= r'C:\\Users\cevans\Desktop\models1\file.xlsm'
def refresher():
    if os.path.exists(file1):
        xl = win32com.client.Dispatch("Excel.Application")
        xl.Workbooks.Open(Filename=file1,ReadOnly=1)
        xl.Visible = True
        xl.Application.Run('Report_Tablerefresh1')
        xl.Workbooks(1).Close(SaveChanges=1)
        xl.Application.Quit()
        del xl
refresher()



Which causes this error:

Traceback (most recent call last):
  File     
"C:/Users/cevans/PycharmProjects/RigLocatorMapPull/Pipe_StorageRefresh.py",
    line 17, in <module>
    refresher()
  File     
"C:/Users/cevans/PycharmProjects/RigLocatorMapPull/Pipe_StorageRefresh.py",
l    ine 10, in refresher
    xl = win32com.client.Dispatch("Excel.Application")
   File "C:\Python27\lib\site-packages\win32com\client\__init__.py",
line 95, in Dispatch
    dispatch, userName =
dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
  File "C:\Python27\lib\site-packages\win32com\client\dynamic.py",
line 104, in _GetGoodDispatchAndUserNamereturn
(_GetGoodDispatch(IDispatch, clsctx), userName)
  File "C:\Python27\lib\site-packages\win32com\client\dynamic.py",
line 84, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
pythoncom.IID_IDispatch)
pywintypes.com_error: (-2146959355, 'Server execution failed', None, None)



I have tried several things to no avail, any suggestions?



-- 

Carl E. Evans MSc.
_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32

Reply via email to