comtypes
comtypes copied to clipboard
errors occured when convert from Word to PDF
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))
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.
THANKS
@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?
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
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.
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 : you are amazing buddy. Thanks a ton.
@robinshion @vasily-v-ryabov @yuen26 @rayoriz
If the issue remains, please re-open.
Encountered the same error with Word 2007 and yuen26 solution works like a charm. Thanks mate :)