This code in Python is not working:
from comtypes import client
word = client.CreateObject("Word.Application")
word.Documents.Open("C:\\test.docx")
I get this error message:
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
doc = word.Documents.Open("test.docx")
AttributeError: 'POINTER(IUnknown)' object has no attribute 'Documents'
Similar code using the class Excel.Appliation also gives the same kind of error. Another test with InternetExplorer.Application worked. So it seems a problem of Office.
I also tested the same code in VBScript and worked.
The code works in Windows7-64bits and Office 2013. The computer where it is not working is Windows10-64bits and Office 365. The Python version in both computers is 3.6-64bits.
This is not a good solution but I think I will be able to live with it. I'm using this code now:
from comtypes import client
word = client.CreateObject("Word.Application", dynamic = True)
word.Visible = True
word.Documents.Open("test.docx")
word.Documents[0].SaveAs("test.pdf", 17)
word.Documents[0].Close()
Important is the word.Visible = True row and the dynamic = True parameter. Without them the Documents collection is not found.
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