How to Change text in header when printing using VBA in Excel?
Tags: tochangetextinheader, vbamacros
Published: 2021-10-01 02:22:49

---
title: How to Change text in header when printing using VBA in Excel?
published: true
date: 2021-09-30 06:58:25 UTC
tags: ToChangeTextInHeader,VBAMacros
canonical_url: https://geekexcel.com/how-to-change-text-in-header-when-printing-using-vba-in-excel/
---

In this tutorial, we will guide you on how to ** change the text in the header when printing using VBA** in Excel. 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.

```
Sub VariableRow()
   Dim intCount As Integer, intCounter As Integer
   Range("A1").Select
   intCount = ExecuteExcel4Macro("INDEX(GET.DOCUMENT(50),1)")
   Sheet1.PageSetup.PrintTitleRows = "1:1"
   For intCounter = 1 To intCount
      Range("A1").Value = "RepetitionLine " & intCounter & ". Page"
      ActiveSheet.PrintOut from:=intCounter, to:=intCounter
   Next intCounter
   Range("A1").Value = "RepetitionLine"
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-96.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>

- Now, 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-62.png)<figcaption>Run the Code</figcaption>

- Finally, you will receive the **text in header** when printing as given below.

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

## Conclusion

We hope that this short tutorial gives you guidelines on how to  **change the text in the header when printing using VBA** in Excel. ** ** 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/) **!!**

**Read Ahead:**

- **[Insert File Name and File Path into Cell, Header or Footer in Excel!!](https://geekexcel.com/insert-file-name-and-file-path-into-cell-header-or-footer-in-excel/)**
- **[Printing a List into Multiple Columns to Fit on Each Printed Page in Excel!!](https://geekexcel.com/printing-a-list-into-multiple-columns-to-fit-on-each-printed-page-in-excel/)**
- **[How to Print Multiple Workbooks/Worksheets from Directories in Excel 365?](https://geekexcel.com/how-to-print-multiple-workbooks-worksheets-from-directories-in-excel-365/)**
- **[Select a printer tray before printing using VBA in Excel](https://geekexcel.com/how-to-select-a-printer-tray-before-printing-using-vba-in-excel/)**
- **[How to Print Pages in Reverse Order in Excel Office 365?](https://geekexcel.com/how-to-print-pages-in-reverse-order-in-excel-office-365/)**