How to print a header on the first page in a multiple pages document and the same content footer in the consecutive pages automatically using VBA.
Headers and footers can be important indicators of the topic in our documents including presentations. The video describes how to insert a header in a many pages document. Also we can insert a footer automatically that can have the same or different content. To save paper we have set the print preview flag to true.
Here’s the complete macro code to perform the task quickly, easily and automatically:
Dim TotalPages As Long
TotalPages = Application.ExecuteExcel4Macro(“GET.DOCUMENT(50)”)
‘MsgBox “The total pages for printing are: ” & TotalPages
.CenterHeader = “SALES BY REGION AND REP”
ActiveSheet.PrintOut From:=1, To:=1, copies:=1, preview:=True, collate:=True
.CenterHeader = “”
.CenterFooter = “SALES BY REGION AND REP”
ActiveSheet.PrintOut From:=2, To:=TotalPages, copies:=1, preview:=True, collate:=True
.CenterFooter = “”
The above macro code has been improved as compared to the code in the video to ensure that the headers and footers are not created permanently.