Changing Font Type in Header VBA Code

RobR1981

New Member
Joined
Sep 11, 2019
Messages
3
Hello Everyone,

I'm getting some odd behavior when I try running some VBA code that updates the font type in a page header. Here is the snippet of code:

Code:
With masterWkbk.Worksheets("Dashboard")
     .PageSetup.RightHeader = "&""Times New Roman,Regular" & Format(Now, "YYYY") & " " & prevQtr & qtrEndingDate
End With
Running the macro places September 30, 2019 in the header.

If I remove the "&""Times New Roman,Regular" portion, I get the correct result:

2019 3rd Quarter / Ending September 30, 2019

Can't figure out what I am doing wrong.

The prevQtr and qtrEndingDate are of course variables and defined above that line of code.
 

Some videos you may like

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,125
Try this:
Code:
        .PageSetup.RightHeader = "&""Times New Roman,Regular"" " & Format(Now, "YYYY") & " " & prevQtr & qtrEndingDate
If you want an explicit font size (e.g. 8):
Code:
        .PageSetup.RightHeader = "&""Times New Roman,Regular""&8 " & Format(Now, "YYYY") & " " & prevQtr & qtrEndingDate
 

Forum statistics

Threads
1,089,692
Messages
5,409,846
Members
403,280
Latest member
sepanikm

This Week's Hot Topics

Top