Basics of VBA / Macros Chapter – 55 (Events Part‑4)

⚡ Macro Developer Toolkit

Copy or Export this Code to VBA

Use these verified developer utilities to run this lesson directly inside your Microsoft Excel Visual Basic Editor.

🖇 View Code Example
Basics of VBA / Macros Chapter – 55 (Events Part-4)
⏱ 1 min readUpdated 12 November 2026

Create a Footer Before Printing

Below we will look at a program in Excel VBA that creates a footer before printing a workbook. Create a Workbook BeforePrint Event. Code added to the Workbook BeforePrint Event will be executed by Excel VBA before you print a workbook. Open the Visual Basic Editor. Double click on This Workbook in the Project Explorer. Choose Workbook from the left drop-down list. Choose BeforePrint from the right drop-down list.

Workbook BeforePrint Event in Excel VBA

Advertisement

To create a footer, add the following code line to the Workbook BeforePrint Event:

ActiveSheet.PageSetup.LeftFooter = ActiveWorkbook.FullName

The PageSetup object contains all page setup attributes (left footer, bottom margin, paper size, left margin, and so on) as properties. Test the program by printing your workbook.

Result:

Advertisement

Footer

✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free Β· AI can be wrong