{"id":68283,"date":"2005-12-21T22:33:00","date_gmt":"2005-12-21T22:33:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/12\/21\/how-can-i-change-the-footer-in-an-excel-spreadsheet\/"},"modified":"2005-12-21T22:33:00","modified_gmt":"2005-12-21T22:33:00","slug":"how-can-i-change-the-footer-in-an-excel-spreadsheet","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-change-the-footer-in-an-excel-spreadsheet\/","title":{"rendered":"How Can I Change the Footer in an Excel Spreadsheet?"},"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! How can I change the footer in an Excel spreadsheet?<BR><BR>&#8212; JA<\/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, JA. Ah, a trick question, huh? As it turns out, there\u2019s no such thing as <I>the<\/I> footer in Excel; instead, Excel has three different footers: the left footer, the center footer, and the right footer. And here\u2019s a script that can change all three of them:<\/P><PRE class=\"codeSample\">Set objExcel = CreateObject(&#8220;Excel.Application&#8221;)\nobjExcel.Visible = True\nSet objWorkbook = objExcel.Workbooks.Add()\nSet objWorksheet = objWorkbook.Worksheets(1)<\/p>\n<p>objWorksheet.PageSetup.LeftFooter = &#8220;Left footer&#8221;\nobjWorksheet.PageSetup.CenterFooter = &#8220;Center footer&#8221;\nobjWorksheet.PageSetup.RightFooter = &#8220;Right footer&#8221;\n<\/PRE>\n<P>As you can see, there really isn\u2019t all that much to this script. We begin by creating an instance of the <B>Excel.Application<\/B> object and then set the <B>Visible<\/B> property to True; that gives us a running instance of Excel that we can see onscreen. We use the <B>Add<\/B> method to add a new workbook, then use this line of code to bind to the first worksheet in the <B>Worksheets<\/B> collection:<\/P><PRE class=\"codeSample\">Set objWorksheet = objWorkbook.Worksheets(1)\n<\/PRE>\n<P>All we have to do now is assign values to <B>LeftFooter<\/B>, <B>CenterFooter<\/B>, and <B>RightFooter<\/B>, all of which happen to be properties of the worksheet\u2019s <B>PageSetup<\/B> object:<\/P><PRE class=\"codeSample\">objWorksheet.PageSetup.LeftFooter = &#8220;Left footer&#8221;\nobjWorksheet.PageSetup.CenterFooter = &#8220;Center footer&#8221;\nobjWorksheet.PageSetup.RightFooter = &#8220;Right footer&#8221;\n<\/PRE>\n<P>Cool.<\/P>\n<P>OK, that\u2019s a good point: it\u2019s possible that you don\u2019t want your center footer to simply read \u201cCenter Footer.\u201d Obviously you can assign any text you want to these footers. In addition, you can also include some of Excel\u2019s <A href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/vbaxl11\/html\/xlidxPageSetupFormatCodes1_HV05201409.asp\" target=\"_blank\"><B>special formatting codes<\/B><\/A> within a footer. For example, here\u2019s a script that uses the current date as the center footer:<\/P><PRE class=\"codeSample\">Set objExcel = CreateObject(&#8220;Excel.Application&#8221;)\nobjExcel.Visible = True\nSet objWorkbook = objExcel.Workbooks.Add()\nSet objWorksheet = objWorkbook.Worksheets(1)<\/p>\n<p>objWorksheet.PageSetup.CenterFooter = &#8220;&amp;D&#8221;\n<\/PRE>\n<P>There\u2019s really nothing to it: we simply use the formatting code <B>&amp;D<\/B> to insert the date. (Note that the formatting code must be enclosed in quotation marks, just like any other string value.) <\/P>\n<P>Here\u2019s a slightly fancier footer, one that gives you a <B>Page 1 of 9<\/B> sort of thing. Notice that we can mix both regular old text and the special formatting codes in the same string value:<\/P><PRE class=\"codeSample\">Set objExcel = CreateObject(&#8220;Excel.Application&#8221;)\nobjExcel.Visible = True\nSet objWorkbook = objExcel.Workbooks.Add()\nSet objWorksheet = objWorkbook.Worksheets(1)<\/p>\n<p>objWorksheet.PageSetup.CenterFooter = &#8220;Page &amp;P of &amp;N&#8221;\n<\/PRE>\n<P>You can see the value we assigned to the footer: <B>Page &amp;P of &amp;N<\/B>. That simply means \u201cPut the following in the footer: the word <I>Page<\/I>, followed by the current page number (&amp;P) followed by the word <I>of<\/I>, followed by the total number of pages in the spreadsheet (&amp;N).\u201d Child\u2019s play.<\/P>\n<P>And now we have a trick question for <I>you<\/I>: If you spell &#8220;sit all day in the tub&#8221; S-O-A-K, and you spell &#8220;a funny story&#8221; J-O-K-E, how do you spell &#8220;the white of an egg?&#8221;<\/P>\n<P>Nope, sorry: the white of an egg is spelled A-L-B-U-M-E-N. (Thank goodness you asked us an Excel footer question instead of a trick question like <I>that<\/I>.)<\/P>\n<P><I>Editor\u2019s Note: You might be thinking that the editor should have stepped in and saved you from such a bad joke, but sometimes it\u2019s easier to let the Scripting Guys (okay, Greg) think they\u2019re (he\u2019s) funny. You can just laugh politely and walk away like this editor tends to do.<\/I><\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I change the footer in an Excel spreadsheet?&#8212; JA Hey, JA. Ah, a trick question, huh? As it turns out, there\u2019s no such thing as the footer in Excel; instead, Excel has three different footers: the left footer, the center footer, and the right footer. And here\u2019s a script that [&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":[710,711,48,49,3,5],"class_list":["post-68283","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-excel-spreadsheet","tag-excel-application","tag-microsoft-excel","tag-office","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I change the footer in an Excel spreadsheet?&#8212; JA Hey, JA. Ah, a trick question, huh? As it turns out, there\u2019s no such thing as the footer in Excel; instead, Excel has three different footers: the left footer, the center footer, and the right footer. And here\u2019s a script that [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68283","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=68283"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68283\/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=68283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=68283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=68283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}