comtypes icon indicating copy to clipboard operation
comtypes copied to clipboard

errors occured when convert from Word to PDF

Open robinshion opened this issue 6 years ago • 7 comments

It is work on my laptop but not work on my office desktop both of them using word 2007

please help

code is :

docxfilepath = os.path.join(CURRENT_DIR,filename)

doc.save(docxfilepath)

wdFormatPDF = 17

word = comtypes.client.CreateObject('Word.Application')
doc = word.Documents.Open(docxfilepath)
doc.SaveAs(PDFfilepath, FileFormat=wdFormatPDF)
doc.Close()
word.Quit()

File "C:\Db\test.py", line 1812, in doc.SaveAs(PDFfilepath, FileFormat=wdFormatPDF) _ctypes.COMError: (-2146824090, None, (u'Command failed', u'Microsoft Word', u'C :\Program Files (x86)\Microsoft Office\Office12\1033\WDMAIN11.CHM', 36966, None))

robinshion avatar Jan 10 '18 21:01 robinshion

It doesn't work on older MS Office versions. Just no SaveAs method or has another params. Not a comtypes problem. The same happens with win32com.client from pyWin32.

vasily-v-ryabov avatar Jan 23 '18 19:01 vasily-v-ryabov

THANKS

robinshion avatar Jan 23 '18 19:01 robinshion

@vasily-v-ryabov Thanks you. I also encounter the same error with MS Office 2007. But I don't know MS Office versions which this code will working with?

yuen26 avatar Dec 08 '18 14:12 yuen26

Finally, I solved this problem. With MS Office 2007, please download and install this add-in: https://www.microsoft.com/en-us/download/details.aspx?id=7

yuen26 avatar Dec 09 '18 04:12 yuen26

Finally, I solved this problem. With MS Office 2007, please download and install this add-in: https://www.microsoft.com/en-us/download/details.aspx?id=7

Hello @yuen26 Can you please tell which add in you installed to resolve this issue? I am facing the same error and this addin is not available for download anymore.

rayoriz avatar Jun 17 '19 20:06 rayoriz

Finally, I solved this problem. With MS Office 2007, please download and install this add-in: https://www.microsoft.com/en-us/download/details.aspx?id=7

Hello @yuen26 Can you please tell which add in you installed to resolve this issue? I am facing the same error and this addin is not available for download anymore.

Hey @rayoriz , I found it. It's Microsoft Save as PDF or XPS add-in. Reference (please Google translate to your language): https://quantrimang.com/cach-don-gian-de-chuyen-file-excel-sang-pdf-118430

yuen26 avatar Jun 18 '19 12:06 yuen26

@yuen26 : you are amazing buddy. Thanks a ton.

rayoriz avatar Jun 18 '19 21:06 rayoriz

@robinshion @vasily-v-ryabov @yuen26 @rayoriz

If the issue remains, please re-open.

junkmd avatar Dec 03 '22 07:12 junkmd

Encountered the same error with Word 2007 and yuen26 solution works like a charm. Thanks mate :)

alexrubis avatar Apr 11 '24 09:04 alexrubis