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

Bob Gailer bgailer at alum.rpi.edu
Sun Oct 31 19:44:59 CET 2004


At 11:12 AM 10/31/2004, Waldemar Osuch wrote:
>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?

Get Steve Roman's Learning Word Programming (O'Reilly). Invaluable 
reference. Will save you hours.

I think Pythonwin will autocomplete after you type doc. if you have run 
MakePy on Word.

>Or do I have to have Word VBA
>window open just to
>see its properties after all.
>
>Waldemar
>_______________________________________________
>Python-win32 mailing list
>Python-win32 at python.org
>http://mail.python.org/mailman/listinfo/python-win32

Bob Gailer
bgailer at alum.rpi.edu
303 442 2625 home
720 938 2625 cell 



More information about the Python-win32 mailing list