How To Insert headers and footers using VBA in Microsoft Excel 2010?
Tags: toinsertheadersandfo, vbamacros
Published: 2021-10-01 02:22:31

---
title: How To Insert headers and footers using VBA in Microsoft Excel 2010?
published: true
date: 2021-09-29 09:16:32 UTC
tags: ToInsertHeadersAndFo,VBAMacros
canonical_url: https://geekexcel.com/how-to-insert-headers-and-footers-using-vba-in-microsoft-excel-2010/
---

In this tutorial, we will guide you on how to  **insert headers and footers using VBA** in Microsoft Excel 2010. Let’s get them below!! Get an official version of MS Excel from the following link: **[https://www.microsoft.com/en-in/microsoft-365/excel](https://www.microsoft.com/en-in/microsoft-365/excel)**

## Example

- Firstly, in the Excel Worksheet, you have to go to the  **Developer Tab.**
- Then, you need to ** ** select the  **Visual Basic**  option under the  **Code**  section.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, you have to  **copy and paste the code**  given below.

```
Option Explicit

Sub InsertHeaderFooter()

Dim wsAs Worksheet
Application.ScreenUpdating = False
 Each wsInThisWorkbook.Worksheets
                   With ws.PageSetup
                                       .LeftHeader = “Company Name:”
                                       .CenterHeader = “Page &P of &N”
                                       .RightHeader = “Printed &D &T”
                                       .LeftFooter = “Path : “ &ActiveWorkbook.Path
                                       .CenterFooter = “Workbook Name: & F”
                                       .RightFooter = “Sheet: &A”
                  End With
Next ws
Set ws = Nothing
Application.ScreenUpdating = True
End Sub

```

- You need to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Save-the-Code-94-1024x467.png)<figcaption>Save the Code</figcaption>

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- You need to choose the  **Macros option**  in the Code section.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Then, you have to make sure that your  **macro name is selected**  and click the  **Run ** button.

![](https://geekexcel.com/wp-content/uploads/2021/09/Run-the-Code-61.png)<figcaption>Run the Code</figcaption>

- Now, you will receive the **Header output** as given below.

![](https://geekexcel.com/wp-content/uploads/2021/09/Footer-Output.png)<figcaption>Footer Output</figcaption>

- Finally, you will receive **Footer output** as given below in Microsoft Excel.

![](https://geekexcel.com/wp-content/uploads/2021/09/Footer-Output-1-1024x109.png)<figcaption>Footer Output</figcaption>

## Verdict

We hope that this tutorial gives you guidelines on how to  **insert headers and footers using VBA** in Microsoft Excel 2010. Please leave a comment in case of any  **queries,**  and don’t forget to mention your valuable  **suggestions**  as well. Thank you so much for Visiting Our Site!! Continue learning on **[Geek Excel](https://geekexcel.com/)!! **Read more on [**Excel Formulas**](https://geekexcel.com/excel-formula/) **!!**

**Related Articles:**

- **[How to Fill Cell References From Multiple Worksheets in Excel?](https://geekexcel.com/how-to-fill-cell-references-from-multiple-worksheets-in-excel/)**
- **[How to Search for a Value in All Tabs in Excel Office 365?](https://geekexcel.com/how-to-search-for-a-value-in-all-tabs-in-excel-office-365/)**
- **[Use COMMAND RIBBON Options in Microsoft Excel 365!](https://geekexcel.com/use-command-ribbon-options-in-microsoft-excel-365/)**
- **[How to Sort Sheets/Worksheets Alphabetically in Excel Office 365?](https://geekexcel.com/how-to-sort-sheets-worksheets-alphabetically-in-excel-office-365/)**
- **[How to Unhide a Worksheet in Microsoft Excel 365?](https://geekexcel.com/how-to-unhide-a-worksheet-in-microsoft-excel-365/)**