Using Python to work with MS Word.

Cy Edmunds cedmunds at NOSPAM.rochester.rr.com
Fri Dec 20 11:33:44 EST 2002


"Anthony Evershed" <anthony.evershed at npl.co.uk> wrote in message
news:2eb85cfb.0212200743.63504bf5 at posting.google.com...
> I have to push data (from an Oracle database or similar, accessed by a
> Python script, and hard-coded contents of variables in the Python
> script) into a document template (.dot file) in Microsoft Word 2000.
> As I am trying to keep as much of the transfer operated outside Word
> as possible, I need to use the Win32/COM interface features of Python
> to:
>
> a. Find the field tags in the template (for my own benefit, I've kept
> them to the form ---NameOfField---).
>
> b. Insert (by whatever means, but quite likely using the Paste command
> in Word.
>
> Does anyone have any ideas as to how to perform these tasks
> (especially the first, about which I have found no documation either
> in books or on the net?
>
> Thanks in advance,
>
> Anthony Evershed

I don't know how to do this either, but I know how I would find out. (I have
done this with Excel using the same process.) Open Word and select View,
Toolbars, Visual Basic. The resulting toolbar has an ocon whose flyby help
says "Visual Basic Editor". Select that. Now select the button whose flyby
help says "Object Browser". In the box to the left of the binoculars type in
"template" (no quotes of course). Intuitive, isn't it?

If your version of Word is different from mine some of these things may not
look the same. Even if it is, you are on your own from here. As I said, I
don't know how to do this myself. But all the features of the COM interface
you are seeking are browsable using this technique. HTH Cy





More information about the Python-list mailing list