Need help adding Arial Bold and font size 12 to VBA

craigwoycheesecpa

New Member
Joined
Dec 2, 2023
Messages
5
Office Version
  1. 365
Platform
  1. Windows
I have tried using the combination of "& Arial, Bold after CenterHeader =, and it does not work. I am a newbie so please be patient.

Sub AddCustomHeaderFooters()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.PageSetup.CenterHeader = Worksheets("Sheet2").Range("B1").Value
ws.PageSetup.LeftHeader = Worksheets("Sheet2").Range("B2").Value
Next ws
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
This is a case where you can learn a lot by using the Macro Recorder. Record yourself changing the font and and bolding (to Arial). The recorded macro will reveal the needed syntax and then you can add it to your macro. And if you cannot figure it out, then posting the recorded macro code will give us a better idea of how to help.
 
Upvote 0
This is a case where you can learn a lot by using the Macro Recorder. Record yourself changing the font and and bolding (to Arial). The recorded macro will reveal the needed syntax and then you can add it to your macro. And if you cannot figure it out, then posting the recorded macro code will give us a better idea of how to help.
Sub AddCustomHeaderFooters()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.PageSetup.CenterHeader = "&""Arial,Font""&12 Worksheets("Sheet2").Range("B1").Value
ws.PageSetup.LeftHeader = Worksheets("Sheet2").Range("B2").Value
Next ws
End Sub

Text is bold does not work. I think it has to do with selecting a range value.

The recorder showed the following:

CenterHeader = "&""Arial,Bold""&12South Central Arkansas Electric Cooperative, Inc."

This assumes I just name the header instead of referencing a cell in a worksheet.
 
Upvote 0
Sub AddCustomHeaderFooters()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.PageSetup.CenterHeader = "&""Arial,Font""&12 Worksheets("Sheet2").Range("B1").Value
ws.PageSetup.LeftHeader = Worksheets("Sheet2").Range("B2").Value
Next ws
End Sub

Text is bold does not work. I think it has to do with selecting a range value.

The recorder showed the following:

CenterHeader = "&""Arial,Bold""&12South Central Arkansas Electric Cooperative, Inc."

This assumes I just name the header instead of referencing a cell in a worksheet.
One sec...I typed font instead of bold, but I don't think it will work if I change.
 
Upvote 0
One sec...I typed font instead of bold, but I don't think it will work if I change.
I managed to solve the problem, but I must say that VBA can be quite finicky in my opinion.

Sub AddCustomHeaderFooters()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.PageSetup.CenterHeader = "&""Arial,Bold""&12 " & Worksheets("Sheet2").Range("B1").Value
ws.PageSetup.LeftHeader = Worksheets("Sheet2").Range("B2").Value
Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,277
Messages
6,124,010
Members
449,139
Latest member
sramesh1024

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