How to Add Custom Header Using Macros (VBA) in Excel Office 365?
Tags: addcustomheaderusing, vbamacros
Published: 2020-10-01 07:04:44

---
title: How to Add Custom Header Using Macros (VBA) in Excel Office 365?
published: true
date: 2020-09-30 12:11:33 UTC
tags: AddCustomHeaderUsing,VBAMacros
canonical_url: https://geekexcel.com/how-to-add-custom-header-using-macros-vba-in-excel-office-365/
---

## Add Custom Header Using Macros in Excel:

In this article, you will learn how to **Add Custom Header Using Macros in Excel Office 365** with an example. Let’s get into this article!! 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)
## **Add Custom Header Using Macros:**

To add a custom header using Macros in the spreadsheet, do as follows.

- On the **Developer Tab, select** the **Visual Basic** option under the **Code** section.

![Select Visual Basic option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Select-Visual-Basic-option-5.png)<figcaption id="caption-attachment-14839">Select Visual Basic option</figcaption>

- You need to activate the sheet where you want to **add a custom header**.
- Kindly, **enter the below code**.

VBA code for Add custom header using Macros in Excel

Sub AddCustomHeader()

Dim inputText As String inputText = InputBox(“Enter your text for the custom header”, “Custom Header”)

‘Enter the custom text to the center header

With ActiveSheet.PageSetup

.LeftHeader = “”

.CenterHeader = inputText

.RightHeader = “”

End With

End Sub

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

![Enter the Source Code](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Enter-the-Source-Code-7.png)<figcaption id="caption-attachment-14847">Enter the Source Code</figcaption>

- You need to open the sheet containing the data. On the **Developer Tab, choose** the **Macros option** in the **Code** section.

![Choose the Macros option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Choose-the-Macros-option-3.png)<figcaption id="caption-attachment-14841">Choose the Macros option</figcaption>

- You need to make sure that your macro is selected and **click** the **Run** button.

![Macro Dialog Box](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Macro-Dialog-Box-8.png)<figcaption id="caption-attachment-14848">Macro Dialog Box</figcaption>

- Now, the **custom Header dialog box** will open and you need to **enter the text** in the text box. Then, **click** the **OK** button.

![Custom Header dialog box](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Custom-Header-dialog-box.png)<figcaption id="caption-attachment-14849">Custom Header dialog box</figcaption>

- Now, the specified text will be added to the header of the spreadsheet.
- If you want to check whether it is added or not, go to the **File Tab, select** the  **Print ** option.

![Choose the File Tab](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Choose-the-File-Tab.png)<figcaption id="caption-attachment-14750">Choose the File Tab</figcaption>

- Now, you can see the result in the print preview window as shown in the below screenshot.

![Result](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Result-18.png)<figcaption id="caption-attachment-14850">Result</figcaption>

## **Summary:**

In this article, you can understand the steps to **Add Custom Header Using Macros in Excel Office 365** with an example. Leave your **suggestions** in the comment section. Thanks for visiting **[Geek Excel.](https://geekexcel.com/)** Keep Learning!!

### Read Also:

- **[Add Date to Header Using Macros](https://geekexcel.com/how-to-add-date-in-header-using-macros-vba-in-excel-office-365/)**
- **[Add date to Footer using Macros](https://geekexcel.com/how-to-add-date-in-footer-using-macros-vba-in-excel-office-365/)**
- [**Unmerge All Cells Using Macros**](https://geekexcel.com/unmerge-all-cells-using-macros-vba-in-excel-office-365/)