excel2003 print sheet's name

nodari

Board Regular
Joined
Jan 8, 2010
Messages
224
Hi

I know how to use Header/Footer manually. But is it possible to do by VBA?

I need that after any user write his name in A1, after print, this name must be on every page (like Header or Footer)
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
This assumes that any change to sell A1 in your worksheet will update the header/footer option. The code should be added to the worksheet that contains the A1 cell that will be updated.

I've included all 6 locations that a header or footer can be entered, so you would have it for reference, but I would suggest you clear out any line that doesn't actually need updated. Move the MyUser variable to which ever section you want it to show in (the quotes would not be required, as shown in the example).

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim MyUser
MyUser = Range("A1").Value
    If Target.Column = 1 And Target.Row = 1 Then
        With ActiveSheet.PageSetup
            .LeftHeader = MyUser
            .CenterHeader = ""
            .RightHeader = ""
            .LeftFooter = ""
            .CenterFooter = ""
            .RightFooter = ""
        End With
        Else
    End If
End Sub
 
Upvote 0
This assumes that any change to sell A1 in your worksheet will update the header/footer option. The code should be added to the worksheet that contains the A1 cell that will be updated.

I've included all 6 locations that a header or footer can be entered, so you would have it for reference, but I would suggest you clear out any line that doesn't actually need updated. Move the MyUser variable to which ever section you want it to show in (the quotes would not be required, as shown in the example).

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim MyUser
MyUser = Range("A1").Value
    If Target.Column = 1 And Target.Row = 1 Then
        With ActiveSheet.PageSetup
            .LeftHeader = MyUser
            .CenterHeader = ""
            .RightHeader = ""
            .LeftFooter = ""
            .CenterFooter = ""
            .RightFooter = ""
        End With
        Else
    End If
End Sub

thank you very much, I think it's exactly what I needed.
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,136
Members
452,890
Latest member
Nikhil Ramesh

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