VBA: Formatting Header Font based on Selection in Worksheet

LinxuSx

New Member
Joined
Feb 5, 2012
Messages
13
Hey guys, I've hit a road block here and need a little help. I'm using VBA to allow users to format a custom header and footer on all tabs. I want them to be able to enter the text and allow them to choose the font size and style; however, I cannot get the font style to pull through.

Below is a snippet of what I have so far that currently works. FontSize is the user selected Font Size and LeftHeaderText is the user entered text.

Code:
.LeftHeader = "&" & ThisWorkbook.Worksheets("Instructions").Range("FontSize") & ThisWorkbook.Worksheets("Parameters").Range("LeftHeaderText")

The variable for Font Style is
Code:
ThisWorkbook.Worksheets("Instructions").Range("FontStyle")

I also know that inserting a header and footer directly through VBA would look like this:
Code:
.LeftHeader = "&""Arial,Regular""&8TEXT GOES HERE"

I cannot figure how to pick up the user entered FontStlye though. Any ideas? :confused:
 
Last edited:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Of course when I admit defeat I find an archair way to do it that works:

Code:
.LeftHeader = "&" & Chr(34) & ThisWorkbook.Worksheets("Instructions").Range("FontStyle") & ",Regular" & Chr(34) & "&" & ThisWorkbook.Worksheets("Instructions").Range("FontSize") & ThisWorkbook.Worksheets("Parameters").Range("LeftHeaderText)

If any one knows of a cleaner way I'm all ears, but this does work!
 
Upvote 0

Forum statistics

Threads
1,215,377
Messages
6,124,598
Members
449,174
Latest member
chandan4057

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