win32com opening Word

0

I am using win32 client to open a microsoft word document. I would like to convert word version to 2016 and I am encountering error

from win32com import client
import pythoncom
pythoncom.CoInitialize()
word = client.Dispatch("Word.Application")
word.Visible = True
doc = word.Documents.Open(r'C:\Users\<username>\Documents\<filepath>\test.docx')
doc.Convert()
doc.Save()
doc.Close()
word.Quit()

and I am having this error from word.Documents.open

    word = client.Dispatch("Word.Application")
  File "C:\Users\username\AppData\Local\Programs\Python\Python38-32\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
    dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
  File "C:\Users\username\AppData\Local\Programs\Python\Python38-32\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "C:\Users\username\AppData\Local\Programs\Python\Python38-32\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147024703, 'OLE error 0x800700c1', None, None)```

How do I fix this?

Thank you!

python
win32com
asked on Stack Overflow Dec 3, 2020 by jinjineos

1 Answer

0

I think that this error says Microsoft word document is not installed in your system.

answered on Stack Overflow Dec 3, 2020 by Yash Makan • edited Dec 3, 2020 by Yash Makan

User contributions licensed under CC BY-SA 3.0