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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,609
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,472
Messages
5,596,354
Members
414,060
Latest member
hermanseck

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top