Fix Excel VBA Footer Font Size for Dynamic Dates
Question details
The user needs to correctly format the font size of a dynamic date inserted into an Excel footer via VBA without layout errors.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Using an Excel VBA macro to define the RightFooter property with a specific font size and a dynamic date pulled from a worksheet cell.
- Observed behavior
- The font-size code is parsed incorrectly by Excel, causing it to concatenate the font size number with the beginning of the date string. As a result, part of the date displays oversized in the worksheet instead of inside the footer.
Ensure your Excel workbook is saved as a Macro-Enabled Workbook (.xlsm) and that you have a backup of your current VBA code before modifying the page setup script.
Add a Space After the Font-Size Code in VBA
Prevent Excel from merging the font size number with the first digits of your dynamic date by adding a trailing space after the size parameter in your VBA script.
When defining header or footer formatting using VBA, Excel uses the ampersand (&) followed by a number to set the font size. If a dynamic text string (like a cell value containing a date) immediately follows this size number without a delimiter, Excel may misinterpret the first digits of your date string as a continuation of the font size.
By explicitly adding a space character right after the font-size number in your formatting string, you force Excel to recognize the end of the formatting instruction and parse the appended cell value correctly.
Press Alt + F11 in your Excel workbook to launch the VBA Editor. In the Project Explorer pane on the left, locate and double-click the module containing your footer macro.
Scroll through your macro script to find the specific line of code that sets the RightFooter (e.g., ActiveSheet.PageSetup.RightFooter = "&\"Calibri\"&18" & Sheets("Startersheet").Range("C2")).
Modify the string by typing a single space immediately after the font size number. For example, change "&18" to "&18 " before the closing quotation mark.
Save your VBA code by clicking the Save icon, then run the macro. Return to your worksheet and open Print Preview (Ctrl + P) to verify that the date now appears correctly in the footer with the intended font size.

Manage VBA Macros Seamlessly with WPS Office
WPS Office provides robust, built-in support for Excel VBA macros, making it easy to automate complex tasks like page setups, custom footers, and dynamic data formatting.
- 1. Download and Install WPS Office: Visit the official WPS website to download and install the free WPS Office suite on your computer.
- 2. Open your Macro-enabled Workbook: Launch WPS Spreadsheets and open your existing .xlsm file that contains your footer formatting macros.
- 3. Access the VBA Editor: Navigate to the Developer tab on the top ribbon and click on the 'Visual Basic' or 'Macros' icon to easily view and edit your VBA code.
- 4. Apply the formatting fix: Add the trailing space after your font size parameter within the code editor and run the macro directly within WPS Spreadsheets.

Frequently Asked Questions
Why does Excel VBA confuse font sizes with dynamic dates in footers?
Excel's header and footer formatting syntax utilizes an ampersand (&) followed by numbers to dictate font sizes. If the variable text appended immediately after the formatting starts with a number (such as a date or a numerical value), Excel reads the combined digits as the font size, resulting in a parsing error and oversized text.
Can I apply bold or italic formatting along with the font size in VBA footers?
Yes. You can use specific formatting codes in your VBA string, such as "&B" for bold or "&I" for italic. These can be chained with your font name and size codes, for example: "&B&18 ".
How do I change the specific font style of a footer using VBA?
You can specify the font name by enclosing it in double quotes preceded by an ampersand within your VBA string. Since the string is already in quotes, you must escape the inner quotes, like this: "&\"Arial,Regular\"&14 ".
Will this VBA footer formatting script work in WPS Office?
Yes, WPS Spreadsheets offers robust support for VBA macros and Excel's PageSetup properties. As long as you have the VBA module enabled in your WPS installation, your footer formatting scripts will execute correctly.




