Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to add sheet name does not work

Status
Not open for further replies.

vba317

Programmer
Mar 5, 2009
708
US
I have written a macro to add the sheet name to the header and the page number to the footer I can't get it to work. Any help would be appreciated.

Tom

Code:
Sub UpdateHeader()
' UpdateHeader Macro
    
    Application.PrintCommunication = True
    Application.PrintCommunication = False
    With ActiveSheet.PageSetup
        .CenterHeader = "&Tab"
        .CenterFooter = "Page & &P &"
    End With
    Application.PrintCommunication = True
   
End Sub
 
I am using excel 2010 . I figured out the initial error of my ways. I believe I have determined the correct formula but an interesting thing happens. When I first run the macro the code is entered into the center header and center footer but in order for me to get the page to read correctly I have to click on the center header and footer. Is there a way to select the header and footer so the macro can do this instead of me.

Code:
Sub UpdateHeader()
' UpdateHeader Macro
    
    Application.PrintCommunication = True
    Application.PrintCommunication = False
    With ActiveSheet.PageSetup
        .CenterHeader = "&[Tab]"
        .CenterFooter = "Page &[Page] "
    End With
    Application.PrintCommunication = True
   
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top