Python / COM / Word

Duncan Smith buzzard at urubu.freeserve.co.uk
Mon Mar 22 09:37:50 EST 2004


"Tim Golden" <tim.golden at viacom-outdoor.co.uk> wrote in message
news:mailman.224.1079947879.742.python-list at python.org...
> DS> I'm having a little trouble trying to automate Word
> DS> (2002).  I'm hoping to be able to create and process
> DS> documents relatively independently of any existing open
> DS> Word documents.
> [...]
> DS> Ideally I'd like to have independent 'Word instances', so I
> DS> can hack around to my heart's content without jeopardising
> DS> documents opened and created by some hapless user (which
> DS> would also be me).
>
> I think this is what you want: (using Word2000, but I doubt it matters)
>
> <interpreter dump>
>
> ActivePython 2.2.3 Build 227 (ActiveState Corp.) based on
> Python 2.2.3 (#42, Nov 13 2003, 09:57:55) [MSC 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import win32com.client
> >>> w1 = win32com.client.DispatchEx ("Word.Application")
> >>> w1.Visible = True
> >>> # (Word Appears; New Document; scribbles a bit...)
> ... w2 = win32com.client.DispatchEx ("Word.Application")
> >>> w2.Visible
> 0
> >>> w2.Visible = True
> >>> # (second Word appears; another New doc. First one still untouched)
> ...
> >>>
>
> </interpreter dump>
>
> TJG
>

Thanks, I'll give it a go.

Duncan





More information about the Python-list mailing list