August 10, 2021

Print Header on First Page

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.

Print a Header on the First page automatically

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:

Sub PrintHeaderOnFirstPage()
Dim TotalPages As Long
TotalPages = Application.ExecuteExcel4Macro(“GET.DOCUMENT(50)”)
‘MsgBox “The total pages for printing are: ” & TotalPages
With ActiveSheet.PageSetup
ActiveSheet.PrintOut From:=1, To:=1, copies:=1, preview:=True, collate:=True
.CenterHeader = “”
ActiveSheet.PrintOut From:=2, To:=TotalPages, copies:=1, preview:=True, collate:=True
.CenterFooter = “”
End With
End Sub

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.

Print Header on First page automatically using Macro

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.