Adding “Page X of Y” pagination type in Word with C#

Adding “Page X of Y” pagination type into a Word document from C# into a Word add-in project can be very difficult. I have spent hours to figure out how to do this. It seems to be a special need for this, because sometimes people are requested to scan documents and miss some pages. Now looking back, code seems to be easy, but believe me, wasn’t easy at all to put pieces side by side to obtain this effect because there is lack of documentation about Word add-ins projects.

foreach(Section section in Globals.ThisAddIn.Application.ActiveDocument.Sections)
                Range footer = section.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                footer.Fields.Add(footer, WdFieldType.wdFieldNumPages);
                footer.InsertAfter(" of ");
                footer.Fields.Add(footer, WdFieldType.wdFieldPage);
                footer.InsertAfter("Page ");

Feel to extend it and use this code. Simple as this you can accomplish what is requested.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s