I am opening a word document in word using python and trying to convert it using this answer on StackOverflow.
My python code:
import win32com.client
word = win32com.client.Dispatch('Word.Application')
wdFormatPDF = 17
doc = word.Documents.Open(path)
doc.SaveAs(file_name, FileFormat=wdFormatPDF)
doc.Close()
word.Quit()
However, when doing so, I am met with this error:
doc.SaveAs(file_name, FileFormat=wdFormatPDF)
File "<COMObject Open>", line 5, in SaveAs
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Word', 'Command failed', 'wdmain11.chm', 36966, -2146824090), None)
Please can you explain what this error means and how to fix my code.