logo
search
VBA & Macro Problems

How to Add a User Name Above the Date in an Excel Footer Using VBA

Anum MushtaqAnum Mushtaq Oct 16, 2026 870 views

Question details

The user needs to add a VBA-generated user name above an existing date and time stamp in an Excel left footer without overwriting the current date format.

How to Add a User Name Above the Date in an Excel Footer Using VBA
Product
Excel
Device & OS
not provided
Scenario
Modifying worksheet page setup properties via VBA to include both a custom string and a formatted date-time stamp on separate lines in the footer.
Observed behavior
When applying the new footer code for the user name, it completely replaces the existing date and time stamp instead of stacking above it.
Before you start

Ensure your workbook is saved as a Macro-Enabled Workbook (.xlsm) and that you have access to the Developer tab to modify the underlying VBA code.

Solution 1Recommended

Combine Strings with a Line Break Character (Chr(10))

Use the VBA Chr(10) function to insert a carriage return between your user name variable and the date-time format, assigning them together to the LeftFooter property.

In Excel VBA, assigning a value to the PageSetup.LeftFooter property overwrites any existing content. To preserve your existing date and time stamp while adding new text above it, you must concatenate the new string, a line break, and the old string into a single command.

1
Open the VBA Editor

Press Alt + F11 to open the Visual Basic for Applications editor, and locate the module or worksheet where your page setup macro is stored.

2
Locate the Footer Code

Find the line of code that sets the left footer, which likely looks like: ActiveSheet.PageSetup.LeftFooter = "&12""Times New Roman""" & Format(Now, "DD MMM YY hh:mm").

3
Insert the Concatenated String

Replace that line with a combined string using Chr(10) for a new line. For example: ActiveSheet.PageSetup.LeftFooter = "SUBMITTED BY: " & Title & wSurname & Chr(10) & "&12""Times New Roman""" & Format(Now, "DD MMM YY hh:mm").

4
Test the Output

Run the macro, then return to your Excel worksheet. Press Ctrl + P to open Print Preview and verify that the user name sits neatly above the formatted date and time in the bottom left corner.

Combine Strings with a Line Break Character (Chr(10))
Formatting Tip: The "&12""Times New Roman""" portion applies specifically to the text following it. If you want the user name to have the same font size and style, you may need to place the formatting tags at the very beginning of the concatenated string.
Advanced Macro Support

Easily Manage VBA Macros and Page Setup with WPS Spreadsheet

WPS Spreadsheet fully supports VBA macros, allowing you to seamlessly run and edit your Page Setup scripts. Whether adjusting footers or automating complex workflows, WPS provides a stable and highly compatible environment.

  1. 1. Open Workbook in WPS: Launch WPS Spreadsheet and open your macro-enabled workbook (.xlsm).
  2. 2. Access the Developer Tab: Navigate to the Developer tab on the top ribbon and click on 'VBA Editor'.
  3. 3. Update the Footer Script: Locate your PageSetup macro and apply the Chr(10) concatenated string method to update the LeftFooter.
  4. 4. Preview and Print: Save your code, return to the spreadsheet, and click Print Preview to confirm the footer layout is correct.
Fully compatible with Microsoft Excel (.xlsx and .xlsm) formatsBuilt-in VBA editor for running and debugging macro scriptsIntuitive print preview and page setup interfaceFree and lightweight alternative to heavy office suites
microsoft office alternative - wps office

Frequently Asked Questions

What does Chr(10) do in an Excel VBA script?

Chr(10) is the VBA character code for a Line Feed. When inserted into a string of text, it forces the characters that follow it to drop down to a new line, which is useful for creating multiline cells, message boxes, and headers or footers.

Can I apply this VBA footer script to all worksheets at once?

Yes. Instead of using ActiveSheet, you can wrap the PageSetup code in a loop: For Each ws In ThisWorkbook.Worksheets, then apply ws.PageSetup.LeftFooter = [your code], and close with Next ws.

How do I make the macro run automatically before I print?

You can place your footer VBA code inside the Workbook_BeforePrint event. Open the 'ThisWorkbook' module in the VBA Editor, select 'Workbook' from the left dropdown and 'BeforePrint' from the right, then paste your code inside the sub.

Why is the font size tag like "&12" required inside the VBA string?

Excel headers and footers use special ampersand (&) formatting codes to define font attributes. Adding "&12" instructs Excel to format the text immediately following the code at exactly 12-point size.