{"id":67353,"date":"2006-05-10T12:36:00","date_gmt":"2006-05-10T12:36:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/05\/10\/how-can-i-add-centered-page-numbers-to-the-footer-of-a-word-document\/"},"modified":"2006-05-10T12:36:00","modified_gmt":"2006-05-10T12:36:00","slug":"how-can-i-add-centered-page-numbers-to-the-footer-of-a-word-document","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-add-centered-page-numbers-to-the-footer-of-a-word-document\/","title":{"rendered":"How Can I Add Centered Page Numbers to the Footer of a Word Document?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! I need to put the page number (centered) in the footer of a Word document. Do you have any suggestions on how I can do that?<BR><BR>&#8212; AW<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, AW. To tell you the truth, the Scripting Guy who writes this column no longer makes suggestions. That\u2019s because of an incident that occurred a few years ago, when someone he works with sent out a blanket email about their latest project, adding, \u201cPlease let me know if you have any suggestions on how we can make this even better.\u201d Being a bit na\u00efve in the ways of the world, our hero actually <I>had<\/I> a couple suggestions, so he helpfully forwarded those along.<\/P>\n<P>You got it: <I>big<\/I> mistake. After being chewed out by the person who sent the email (\u201cA lot of people put a lot of time and effort into this project and all you can do is find things that are wrong with it!\u201d) and that person\u2019s manager and <I>his<\/I> manager (\u201cYou should know better than to give her any suggestions\u201d), this particular Scripting Guy vowed never to make another suggestion as long as he lived, a vow he has stuck to for nearly three years now. <\/P>\n<P>Also a vow which, interestingly enough, hasn\u2019t seemed to upset anyone else in the least. No one seems to miss his help at all.<\/P>\n<P>So, no, AW, we don\u2019t have any suggestions for you; we don\u2019t do suggestions. Instead, the best we can do is offer you a script that puts the page number (centered) in the footer of a Word document:<\/P><PRE class=\"codeSample\">Const wdAlignPageNumberCenter = 1<\/p>\n<p>Set objWord = CreateObject(&#8220;Word.Application&#8221;)\nobjWord.Visible = True\nSet objDoc = objWord.Documents.Add()<\/p>\n<p>objDoc.Sections(1).Footers(1).PageNumbers.Add(wdAlignPageNumberCenter)\n<\/PRE>\n<P>Yes, it <I>is<\/I> a simple little script, isn\u2019t it? We start out by defining a constant named wdAlignPageNumberCenter and setting the value to 1; this tells the script that we want the page number centered within the footer. What if we change our mind and decide that we <I>don\u2019t<\/I> want the page number centered? That\u2019s OK; we can use any of the following constants and their values:<\/P>\n<TABLE id=\"EPD\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Constant<\/B><\/P><\/TD>\n<TD>\n<P class=\"lastInCell\"><B>Value<\/B><\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdAlignPageNumberCenter<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">1<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdAlignPageNumberInside<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">3<\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdAlignPageNumberLeft<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">0<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdAlignPageNumberOutside<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">4<\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdAlignPageNumberRight<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">2<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>After defining our constant we use these three lines of code, which create a visible instance of the <B>Word.Application<\/B> object and then give us a new, blank document to work with:<\/P><PRE class=\"codeSample\">Set objWord = CreateObject(&#8220;Word.Application&#8221;)\nobjWord.Visible = True\nSet objDoc = objWord.Documents.Add()\n<\/PRE>\n<P>Once we\u2019ve done that we can add the page numbers with a single line of code:<\/P><PRE class=\"codeSample\">objDoc.Sections(1).Footers(1).PageNumbers.Add(wdAlignPageNumberCenter)\n<\/PRE>\n<P>What we\u2019re doing here is creating a <B>PageNumbers<\/B> object tied to the first footer in the first, and only, section of our document; that\u2019s what objDoc.Sections(1).Footers(1) is all about. At the same time, we\u2019re calling the <B>Add<\/B> method to add page numbers to the footer, passing along the constant wdAlignPageNumberCenter to indicate that we want the page numbers centered. And that, as they say, is that.<\/P>\n<P>Of course, there are plenty of other options we can apply to page numbers, far more than we can cover in this one column. (For more information, check out the <A href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/vbawd11\/html\/woobjPageNumbers1_HV05212440.asp\" target=\"_blank\"><B>Microsoft Word VBA Language Reference<\/B><\/A> on MSDN.) Just to whet your appetite, however, we\u2019ll give you one example. The following script defines a constant named wdPageNumberStyleLowercaseRoman and then assigns that constant to the <B>NumberStyle<\/B> property:<\/P><PRE class=\"codeSample\">Const wdAlignPageNumberCenter = 1\nConst wdPageNumberStyleLowercaseRoman = 2<\/p>\n<p>Set objWord = CreateObject(&#8220;Word.Application&#8221;)\nobjWord.Visible = True\nSet objDoc = objWord.Documents.Add()<\/p>\n<p>objDoc.Sections(1).Footers(1).PageNumbers.Add(wdAlignPageNumberCenter)\nobjDoc.Sections(1).Footers(1).PageNumbers.NumberStyle = wdPageNumberStyleLowercaseRoman\n<\/PRE>\n<P>What this will do is &#8211; sorry, what was that? Wow; you\u2019re right: that displays page numbers as lowercase Roman numerals. Very perceptive of you.<\/P>\n<P>Hey, wait a second: you guys aren\u2019t cheating and reading ahead are you? That\u2019s what we thought.<\/P>\n<P>Here, by the way, are the other allowed page number styles. Bear in mind that, depending on your language settings, some of these might not make much sense (or make much difference in your document):<\/P>\n<TABLE id=\"EXF\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Constant<\/B><\/P><\/TD>\n<TD>\n<P class=\"lastInCell\"><B>Value<\/B><\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleArabic<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">0<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleArabicFullWidth<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">14<\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleArabicLetter1<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">46<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleArabicLetter2<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">48<\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleHanjaRead<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">41<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleHanjaReadDigit<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">42<\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleHebrewLetter1<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">45<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleHebrewLetter2<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">47<\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleHindiArabic<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">51<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleHindiCardinalText<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">52<\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleHindiLetter1<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">49<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleHindiLetter2<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">50<\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleKanji<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">10<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleKanjiDigit<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">11<\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleKanjiTraditional<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">16<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleLowercaseLetter<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">4<\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleLowercaseRoman<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">2<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleNumberInCircle<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">18<\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleNumberInDash<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">57<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleSimpChinNum1<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">37<\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleSimpChinNum2<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">38<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleThaiArabic<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">54<\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleThaiCardinalText<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">55<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleThaiLetter<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">53<\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleTradChinNum1<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">33<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleTradChinNum2<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">34<\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleUppercaseLetter<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">3<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleUppercaseRoman<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">1<\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">wdPageNumberStyleVietCardinalText<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">56<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>And, yes, now that you mention it sometimes it <I>is<\/I> hard to go through the day without making any suggestions. After all, this Scripting Guy has been making suggestions for 40 years, and never <I>once<\/I> has anyone taken him up on one of those suggestions. That\u2019s like Cal Ripken\u2019s record for consecutives games played in Major League baseball: it\u2019s inevitable, but you still hate to see a streak like that come to an end. (Although, like boxer Rocky Marciano, we suppose there\u2019s also merit in retiring with a perfect record.)<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! I need to put the page number (centered) in the footer of a Word document. Do you have any suggestions on how I can do that?&#8212; AW Hey, AW. To tell you the truth, the Scripting Guy who writes this column no longer makes suggestions. That\u2019s because of an incident that occurred [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[84,49,3,5],"class_list":["post-67353","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-microsoft-word","tag-office","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! I need to put the page number (centered) in the footer of a Word document. Do you have any suggestions on how I can do that?&#8212; AW Hey, AW. To tell you the truth, the Scripting Guy who writes this column no longer makes suggestions. That\u2019s because of an incident that occurred [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=67353"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67353\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=67353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=67353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=67353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}