[python-win32] Re: Headers and Footers in Word

Roger Upole rwupole at msn.com
Thu Jun 21 06:56:51 CEST 2007


> I've been trying to figure out how to insert data into the header and footer
> objects of a MS Word document. I've read the Word Object Model Overview on
> http://msdn2.microsoft.com/en-us/library/kw65a0we(VS.80).aspx and have the
> Hammond's Python Programming on Win32 book. The I've tried fiddling with the
> MSDN code and have been unsuccessful. The book doesn't discuss headers and
> footers. Does anyone know how to do it?

Here's a translation of this example:
http://msdn2.microsoft.com/en-us/library/ms178795(VS.80).aspx


import win32com.client
w=win32com.client.gencache.EnsureDispatch('Word.Application',0)
w.Visible=1
w.Documents.Open('somedocument.doc')
s=w.ActiveDocument.Sections[0]
s.Footers(win32com.client.constants.wdHeaderFooterPrimary).Range.Text='I am a footer'

        Roger



More information about the Python-win32 mailing list