Saturday, April 20, 2019

Header and footer


Add Header/Footer Date
Use this code to add a date into the header or footer in your worksheet. You can edit this code for switching from header to footer.
Sub dateInHeader()
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = "&D"
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
End With
ActiveWindow.View = xlNormalView
End Sub
Custom Header/Footer
If you want to insert a custom header then this code is for you. Run this code, enter custom value in the input box. To change the alignment of header or footer you can edit the code.
Sub customHeader()
Dim myText As Stringmy
Text = InputBox("Enter your text here", "Enter Text")
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = myText
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
End With
End Sub

No comments:

Post a Comment