How to Add Date in Header Using Macros (VBA) in Excel Office 365?
Tags: adddateinheaderusing, vbamacros
Published: 2020-09-29 09:39:25

---
title: How to Add Date in Header Using Macros (VBA) in Excel Office 365?
published: true
date: 2020-09-29 07:05:23 UTC
tags: AddDateinHeaderUsing,VBAMacros
canonical_url: https://geekexcel.com/how-to-add-date-in-header-using-macros-vba-in-excel-office-365/
---

## Add Date in Header Using Macros:

In this post, we are going to see how to **Add Date in Header Using Macros (VBA) in Excel Office 365** with the best example. Let’s jump 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 Date in Header Using Macros:**

- 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-3.png)<figcaption id="caption-attachment-14745">Select Visual Basic option</figcaption>

- You have to activate the sheet where you want to add a date in the header in Excel.
- Now, enter the below code.

VBA code for Add date in header using Macros in Excel

Sub AddDateInHeader()

‘Here, we used the center header to show the date

With ActiveSheet.PageSetup

.LeftHeader = ” “

.CenterHeader = “&D”

.RightHeader = ” “

End With

ActiveWindow.View = xlNormalView

End Sub

- From the above code, **“&D”** represents the date value and **“LeftHeader, CenterHeader, RightHeader” ** represents the position of the date in the header section of the sheet.
- 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-4.png)<figcaption id="caption-attachment-14746">Enter the Source Code</figcaption>

- You have 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-2.png)<figcaption id="caption-attachment-14747">Choose the Macros option</figcaption>

- You have 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-5.png)<figcaption id="caption-attachment-14748">Macro dialog box</figcaption>

- Now, the date will be added to the header.
- 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 that the date is added in the header of the spreadsheet as shown in the below screenshot.

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

## **Closure:**

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