Unusual Header Title via VBA

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,922
Office Version
  1. 365
Platform
  1. Windows
Hi,

Have the following code attached to a button in my sheet:
Code:
Private Sub CommandButton1_Click()

Dim msg As String

msg = "Enter date tracking error is for: (dd mmmm yyyy):"

With ActiveSheet.PageSetup
    .CenterHeader = "European Focus: " & InputBox(msg, "Date of Tracking Error", Range("TEDate"))
    .LeftFooter = "Path: " & ActiveWorkbook.Path & "\" & ActiveWorkbook.Name
End With

End Sub

Range("TEDate") has formula: =TEXT(WORKDAY(TODAY(),-1, "DD MMMM YYYY")

Which today would give a value of 12 August 2011, yet after I run the above code, when I click on print preview, the central header shows:
"European Focus: 14 August 2011"

I tried including msgbox CenterHeader after the .CenterHeader line and this gave a message of "European Focus: 12 August 2011" so why is it when I click on print preview it shows 14 August?

Thank you for suggestions in advance,
Jack
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
It works fine for me!?!?!? What do you get for ActiveSheet.Name in debugging? Is it the sheet you expect?
 
Upvote 0
Hi Glenn,

Don't know, haven't checked that! But the button is on (and hence) clicked from the activesheet I'm having this problem on.. I'll check and post back.

Ta,
Jack

PS I'll be in your sunny part of the world in October, indoor surfing up in Milton Keynes, great fun, highly recommend it if you've not done it before!
 
Upvote 0
Proper weird, changed the code to:
Code:
Private Sub CommandButton1_Click()

Dim msg As String

msg = "Enter date tracking error is for: (dd mmmm yyyy):"

With Sheets("Summary")
    MsgBox ActiveSheet.Name 'This, as expected gives the right sheet name
    With .PageSetup
        .CenterHeader = "European Focus: " & InputBox(msg, "Date of Tracking Error", Range("TEDate"))
        .LeftFooter = "Path: " & ActiveWorkbook.Path & "\" & ActiveWorkbook.Name
    End With
End With

End Sub
It's definitely on the sheet I want but print preview still shows the header as 14 August rather than 12th..
 
Upvote 0
Indoor surfing? Now that does sound weird. Only joking :-) ... I might give that a try one day.

So, the sheet being processed is the right one ... I don't see how it could not work, sorry :-(
 
Upvote 0
It's really good fun and the water's warm!

No idea regarding this issue, see if anyone else replies or I'll just find a more manual way to do it..
 
Upvote 0

Forum statistics

Threads
1,224,593
Messages
6,179,791
Members
452,942
Latest member
VijayNewtoExcel

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