[python-win32] win32com: How to Dispatch a Word document

Waldemar Osuch waldemar.osuch at gmail.com
Sun Oct 31 19:12:43 CET 2004


I would like to have a Word Document instance with all methods and
properties visible during interactive session.  This is my currnet
apporach:

PythonWin 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit
(Intel)] on win32.
Portions Copyright 1994-2004 Mark Hammond (mhammond at skippinet.com.au)
- see 'Help/About PythonWin' for further copyright information.
>>> from win32com.client import gencache, Dispatch
>>> gencache.EnsureModule('{00020905-0000-0000-C000-000000000046}', 0,
8, 1, bForDemand=True)
<module 'win32com.gen_py.00020905-0000-0000-C000-000000000046x0x8x1'
from 'C:\DOCUME~1\osuchw\LOCALS~1\Temp\gen_py\2.3\00020905-0000-0000-C000-000000000046x0x8x1\__init__.py'>
>>> word = Dispatch('Word.Application')
>>> word
<win32com.gen_py.Microsoft Word 9.0 Object Library._Application
instance at 0x18074720>
>>> doc = word.Documents.Add()
>>> doc
<win32com.gen_py.None.Document>

As you can see I am getting a dynamic object not knowing its methods/properties.
What I would like to get is:
>>> doc = Dispatch('Word.Document')
>>> doc
<win32com.gen_py.Microsoft Word 9.0 Object Library._Document instance
at 0x37038040>
>>> 

Is there a way to get what I want?  Or do I have to have Word VBA
window open just to
see its properties after all.

Waldemar


More information about the Python-win32 mailing list