3

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
My answer is the first line I wrote and is different from the answer provided by the link. I added the link to supplement my answer with another possibility. Maybe the link should be deleted?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.