Add page number to a Word document using Python
Question: Is there a way to add page numbers to the lower right corner of a Word
document using Python win32com? I am able to add headers and footers, but I
can't find a way to add page numbers in the format PageNumber of TotalPages
(for example: 1 of 5)

Below is the code to add centered headers and footers to a page

    
    
    from win32com.client import Dispatch as MakeDoc
    filename = name + '.doc'
    WordDoc = MakeDoc("Word.Application")
    WordDoc = WordDoc.Documents.Add()
    WordDoc.Sections(1).Headers(1).Range.Text = name
    WordDoc.Sections(1).Headers(1).Range.ParagraphFormat.Alignment = 1
    WordDoc.Sections(1).Footers(1).Range.Text = filename
    WordDoc.Sections(1).Footers(1).Range.ParagraphFormat.Alignment = 1
    

Thanks


Answer: To insert page numbers use the following statements:

    
    
    WordDoc.Sections(1).Footers(1).PageNumbers.Add(2,True)
    WordDoc.Sections(1).Footers(1).PageNumbers.NumberStyle = 57
    

However, the format of the page number is -page number-. Documentation for
inserting the page number is [here](http://msdn.microsoft.com/en-
us/library/bb178815%28v=office.12%29.aspx), and the one for the number style
is [here](http://msdn.microsoft.com/en-
us/library/bb237910%28v=office.12%29.aspx)

