Discussion:
[python-win32] odd problem with Microsoft Word
Kelie
2007-03-17 07:30:02 UTC
Permalink
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."
Ross McKerchar
2007-03-18 11:20:45 UTC
Permalink
Post by Kelie
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
AttributeError: '<win32com.gen_py.Microsoft Office 11.0 Object
Library.DocumentProperties instance at 0x28416160>' object has no attribute 'Add'
When you use early bound code everything becomes case sensitive when it
wasn't before. Admmitedly, however 'Add' with an uppercase A does seem
right for office.

Another less well documented difference I've found when using early
binding is that keyword arguments work when they didn't before. I doubt
it's relevant but worth bearing in mind.

HTH.

-ross
Kelie
2007-03-19 00:18:35 UTC
Permalink
Post by Ross McKerchar
When you use early bound code everything becomes case sensitive when it
wasn't before. Admmitedly, however 'Add' with an uppercase A does seem
right for office.
Thanks for your reply Ross. But it seems to me early-binding is not the cause of
problem, at least not from Microsoft Word. As i mentioned the code runs fine
after i ran makepy on Word 2003's object library "Microsoft Word 11.0 Object
Library (8.3)". But after i used makepy on Microsoft Office 2003's object
library "Microsoft Office 11.0 Object Library (2.3)", the code stopped working.
Seems there is something conflicting between these two object libraries. i'm
totally guessing.

Loading...