Thank you in advance.
Paul
AFAIK there is no way to insert a formula into the header/footer
definition. You have to use the workbook event Before_print to insert
cell values into the header. e.g.
Private Sub Workbook_BeforePrint(Cancel As Boolean)
ActiveSheet.PageSetup.CenterHeader = Range("A1").Text
End Sub
Put this into the workbook code module. The cell value of A1 will be
inserted.
HTH
Frank
I've been trying to use the Workbook_BeforePrint event in the way you
described, but I've had the problem that it doesn't usually update the page
header every time I print. For some reason, I have to go into Print Preview
before it updates the page header. My workaround has been to call a
separate Sub procedure from the code that prints the page. I call that Sub
right before the line that prints the page, and that sub sets the header
with ActiveSheet.PageSetup. . . . etc.
I don't know why my Workbook_BeforePrint event won't reset the page header
until I open Print Preview, either manually or with VBA, but I find I need
Print Preview to make it load the settings into the header.
I suppose I could live with the workaround I described above, but I thought
it might be simpler if you could put a cell reference directly in the
header. Like you, I haven't been able to figure out a way to get one to
work. It seems to interpret everything I type in there as a literal string.
Again, thank you for responding.
Paul
> I've been trying to use the Workbook_BeforePrint event in the way you
> described, but I've had the problem that it doesn't usually update
> the page header every time I print.
[snip]
That's strange. I use this event quite often and have never encountered
any problems.
> I suppose I could live with the workaround I described above, but I
> thought it might be simpler if you could put a cell reference
> directly in the header. Like you, I haven't been able to figure out
> a way to get one to work. It seems to interpret everything I type in
> there as a literal string.
I think this is just one of the missing functionalty mysteries os MS
Excel :-) AFAIK there simply is NO way to use a cell reference in the
header/footer section. Maybe Microsoft will change this in a future
release.... ;-)
Frank
Instead of:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
ActiveSheet.PageSetup.CenterHeader = Range("A1").Text
End Sub
You could be more specific:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
with worksheets("sheet1")
.PageSetup.CenterHeader = .Range("A1").Text
end with
End Sub
(Change "sheet1" to the correct name.)
--
Dave Peterson
ec3...@msn.com
If ActiveSheet.Name = "dataEntry" Then . . .
So it would seem that can't be the problem.
Others have said they haven't enountered this problem, so I don't know why
it doesn't work in my application. I guess I'll just use that workaround I
described by calling a different sub to reset the page headers.
Paul