Stuck my foot in it and now feel obligated to answer a newsgroup question.
So... help me out, guys. How is this accomplished?
Let's assume I want A1's value to appear in my header.
Stuck my foot in it and now feel obligated to answer a newsgroup question.
So... help me out, guys. How is this accomplished?
Let's assume I want A1's value to appear in my header.
~Anne Troy
Hi Anne,
This is a workbookbeforePrint event that adds the cell value from one sheet into each worksheets header.
Option Explicit Private Sub Workbook_BeforePrint(Cancel As Boolean) Dim WS As Worksheet For Each WS In Worksheets WS.PageSetup.LeftHeader = Worksheets("Sheet1").Range("A3").Value Next WS End Sub
Steve
"Nearly all men can stand adversity, but if you want to test a man's character, give him power."
-Abraham Lincoln
Hi Anne,
I have no idea if this can be done without code, so maybe I'll learn something here...
VBA ways:
HTH,Sub AddHeader() 'Add A1 from active sheet to active sheet's header With ActiveSheet.PageSetup .LeftHeader = Range("A1").Value End With End Sub Sub AddHeaderToAll_1() 'Add A1 from each sheet to header Dim ws As Worksheet For Each ws In ActiveWorkbook.Worksheets ws.PageSetup.LeftHeader = ws.Range("A1").Value Next ws End Sub Sub AddHeaderToAll_2() 'Add A1 from active sheet to each sheets's header Dim ws As Worksheet For Each ws In ActiveWorkbook.Worksheets ws.PageSetup.LeftHeader = ActiveSheet.Range("A1").Value Next ws End Sub
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
Any reason this wouldn't work Ken?
Option Explicit 'Add A1 from active sheet to each sheets's header Private Sub Workbook_BeforePrint(Cancel As Boolean) ActiveSheet.PageSetup.LeftHeader = ActiveSheet.Range("A1").Value End Sub
Steve
"Nearly all men can stand adversity, but if you want to test a man's character, give him power."
-Abraham Lincoln
Not at all. It just runs every time you print, mine runs once. If the value of the range is always changing and needs updating frequently, then yours would be the right way to go. If its pretty stagnant, then mine saves that extra milisecond that no one would notice anyway!
Just different ways to skin a cat, really...
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
That makes sense, Thanks Ken..
Steve
"Nearly all men can stand adversity, but if you want to test a man's character, give him power."
-Abraham Lincoln
I have poked at this several times and concluded each time that the only reliable method was to use code.Originally Posted by kpuls
There are lots of things re the management of headers and footers that could be improved
"It's not just the due date that's important, it's also the do date" [MWE]
When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.
Well then...
I guess some variants of these should make it into the KB then.
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!