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.
I had the same error. In my case, I did not have write permissions in the directory I was saving to.
See also: Error pywintypes.com_error occur when convert files docx to files pdf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With