View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
Tim Zych Tim Zych is offline
external usenet poster
 
Posts: 389
Default Before Print Problem

Hmm, it works for me. If you try this in a new workbook, does the same
behavior occur? Does this occur for a different printer? I'm wondering if
there's a page setup configuration / zoom factor / page breaks / preview
mode / which sheet is active / how is printing being invoked or some other
page-setup issue that is causing the code to be buggy.


--
Tim Zych
SF, CA

"Karen53" wrote in message
...
This is so frustrating! What is going on?

The immediate window shows the code executing with the correct value for
the
header variable, yet the header on the worksheet does not change.

If I do a print preview, the worksheet header changes.

I've run out of things to try.

--
Thanks for your help.
Karen53


"Tim Zych" wrote:

Try assigning it to a variable so the string can be fully resolved before
it
goes into the header, e.g.

Dim HdrVal As String
HdrVal = "&C&14&B" & SumbyLineItempg.Range("E2").Value & _
"&4" & vbCrLf & "&12&A" & vbCrLf & " "
Debug.Print HdrVal
.CenterHeader = HdrVal

Then you can inspect it too to help narrow down the problem.

--
Tim Zych
SF, CA

"Karen53" wrote in message
...
Hi,

I have the following BeforePrint routine in my ThisWorkbook module
which
places a custom header on pages based on the value of cells in the
sheet.
It
worked except now if the value of the cell changes, it is not picking
up
the
change and stays with the old value in the header. This there
something
I
am missing?

Private Sub Workbook_BeforePrint(Cancel As Boolean)

'add custom header to pages before printing

With SumbyLineItempg.PageSetup
.CenterHeader = "&C&14&B" & SumbyLineItempg.Range("E2").Value &
_
"&4" & vbCrLf & "&12&A" & vbCrLf & " "
End With

With LineItemspg.PageSetup
.CenterHeader = "&C&14&B" & LineItemspg.Range("C2").Value & _
"&4" & vbCrLf & "&12&A" & vbCrLf & " "
End With

With MainPagepg.PageSetup
.CenterHeader = "&C&14&B" & MainPagepg.Range("B1").Value & _
"&4" & vbCrLf & "&12&A" & vbCrLf & " "
End With

End Sub
--
Thanks for your help.
Karen53