[python-win32] odd problem with Microsoft Word

Kelie kf9150 at gmail.com
Sat Mar 17 08:30:02 CET 2007


Hello,

The simple code shown below runs fine. It adds a custom document property to the
active word document. But as soon as i use makepy on the "Microsoft Office 11.0
Object Library (2.3)", i get an AttributeError when run the same code:
AttributeError: '<win32com.gen_py.Microsoft Office 11.0 Object
Library.DocumentProperties instance at 0x28416160>' object has no attribute 'Add'

I tested a few times and the behavior is consistent. Btw, the code also runs
fine after i use makepy on the "Microsoft Word 11.0 Object Library (8.3)".
Because i wanted to access some constants which are common to Microsoft Office
applications, i tried use makepy on the office11 object library which seems to
be causing the problem. 

Btw, i'm using Office 2003 on WinXP pro. Thanks for you help.

kelie

import win32com.client
wdApp = win32com.client.gencache.EnsureDispatch("Word.Application")
doc = wdApp.ActiveDocument
doc.CustomDocumentProperties.Add("VarName", False, 4, "VarValue")
print "Done."



More information about the Python-win32 mailing list