Header Issue

cstimart

Well-known Member
Joined
Feb 25, 2010
Messages
1,180
Am using the following to attempt to use VBA to create my document header.

fName is a string variable that extracts the .xls/.xlsx/.xlsm from the filename. the pertinent portion of the code that I am using (with no success) is as follows

Code:
Activesheet.PageSetup.CenterHeader = "&C&B""Arial""&20" & fName
Help, Please.
 
My file name currently is "2011 QC Results.xlsm"

After running the macro, the header wants to read as "QC Results"...omitting the "2011 " portion...in addition the "QC" is in a HUGE font in the lower 1/3 of the page.
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I believe I have found the issue...still no resolution.

My file name currently is "2011 QC Results.xlsm".....I changed it to "QC Results.xlsm" and everything works fine. Apparently, the code is using the "2011" to max out the font size.

:banghead:
 
Upvote 0
Solved

Needed to put a space after the Font size of 20!

Code:
Sub Foo()
    Dim Pos As String
    Dim headerText As String

    With ActiveSheet
        headerText = ThisWorkbook.Name
        Pos = InStr(1, headerText, ".", vbTextCompare) - 1
        headerText = Left(headerText, Pos)
    End With

    ActiveSheet.PageSetup.CenterHeader = "&""Arial,Bold""&20 " & headerText
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,459
Members
452,915
Latest member
hannnahheileen

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