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.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
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
 
Upvote 0

Forum statistics

Threads
1,224,559
Messages
6,179,515
Members
452,921
Latest member
BBQKING

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
Back
Top