BeforePrint help

G

Guest

Private Sub Workbook_BeforePrint(Cancel As Boolean)
With ActiveWorkbook.Sheets
N = WorkSheets("Cover").Range("MyPages").Value
If Range("A1") >= 1 Then
ActiveSheet.PageSetup.RightHeader = "&""Arial Narrow,Regular""&8Page
&P of " & N
Else
ActiveSheet.PageSetup.RightHeader = "" '< Runs out back door
hugs a few trees>
End If
End With
End Sub

Works but only changes heading on active sheet. I want to change the header
on every sheet (5 or 9 depending).
I don't want to name the workbook as it may change. Path may change as well.
Do I need loop statement? Quite happy I got this far.
The P is actually [P] - [PAGES], is there a way to easily display these
hidden characters?

I found "VB help, with, control flow keyword summary", seems to help. Any
other suggested sources?
Thanks Lou
 
N

Nigel

Put a loop around the header set up as follows..........

Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
If Range("A1") >= 1 Then
ActiveSheet.PageSetup.RightHeader = "&""Arial Narrow,Regular""&8Page&P
of " & N
Else
ActiveSheet.PageSetup.RightHeader = "" '< Runs out back door hugs
a few trees>
End If
Next
 
N

Nigel

Sorry did not change your code to set the header on the specific
sheet........

Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
If wks.Range("A1") >= 1 Then
wks.PageSetup.RightHeader = "&""Arial Narrow,Regular""&8Page&Pof " & N
Else
wks.PageSetup.RightHeader = "" '< Runs out back door hugs a few
trees>
End If
Next



--
Cheers
Nigel



Nigel said:
Put a loop around the header set up as follows..........

Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
If Range("A1") >= 1 Then
ActiveSheet.PageSetup.RightHeader = "&""Arial Narrow,Regular""&8Page&P
of " & N
Else
ActiveSheet.PageSetup.RightHeader = "" '< Runs out back door hugs
a few trees>
End If
Next

---
Cheers
Nigel

Rookie 1st class said:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
With ActiveWorkbook.Sheets
N = WorkSheets("Cover").Range("MyPages").Value
If Range("A1") >= 1 Then
ActiveSheet.PageSetup.RightHeader = "&""Arial Narrow,Regular""&8Page
&P of " & N
Else
ActiveSheet.PageSetup.RightHeader = "" '< Runs out back door
hugs a few trees>
End If
End With
End Sub

Works but only changes heading on active sheet. I want to change the header
on every sheet (5 or 9 depending).
I don't want to name the workbook as it may change. Path may change as well.
Do I need loop statement? Quite happy I got this far.
The P is actually [P] - [PAGES], is there a way to easily display these
hidden characters?

I found "VB help, with, control flow keyword summary", seems to help. Any
other suggested sources?
Thanks Lou
 
G

Guest

Thanks Nigel
I think this is beginning to make sense.
Lou

Nigel said:
Sorry did not change your code to set the header on the specific
sheet........

Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
If wks.Range("A1") >= 1 Then
wks.PageSetup.RightHeader = "&""Arial Narrow,Regular""&8Page&Pof " & N
Else
wks.PageSetup.RightHeader = "" '< Runs out back door hugs a few
trees>
End If
Next



--
Cheers
Nigel



Nigel said:
Put a loop around the header set up as follows..........

Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
If Range("A1") >= 1 Then
ActiveSheet.PageSetup.RightHeader = "&""Arial Narrow,Regular""&8Page&P
of " & N
Else
ActiveSheet.PageSetup.RightHeader = "" '< Runs out back door hugs
a few trees>
End If
Next

---
Cheers
Nigel

Rookie 1st class said:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
With ActiveWorkbook.Sheets
N = WorkSheets("Cover").Range("MyPages").Value
If Range("A1") >= 1 Then
ActiveSheet.PageSetup.RightHeader = "&""Arial Narrow,Regular""&8Page
&P of " & N
Else
ActiveSheet.PageSetup.RightHeader = "" '< Runs out back door
hugs a few trees>
End If
End With
End Sub

Works but only changes heading on active sheet. I want to change the header
on every sheet (5 or 9 depending).
I don't want to name the workbook as it may change. Path may change as well.
Do I need loop statement? Quite happy I got this far.
The P is actually [P] - [PAGES], is there a way to easily display these
hidden characters?

I found "VB help, with, control flow keyword summary", seems to help. Any
other suggested sources?
Thanks Lou
 
G

Guest

Final:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
'Add Header Macro
N = WorkSheets("Cover").Range("MyPages").Value
Dim wks As Worksheet
For Each wks In ActiveWorkbook.WorkSheets
If wks.Range("A1") >= 1 Then
wks.PageSetup.RightHeader = "&""Arial Narrow,Regular"_
"&8Page &P of " & N
Else
wks.PageSetup.RightHeader = ""
End If
Next
End Sub

It works PERFECTLY ... WOOHOO!!!
Thanks again to both you and Tom
Health and Happiness Lou

Rookie 1st class said:
Thanks Nigel
I think this is beginning to make sense.
Lou

Nigel said:
Sorry did not change your code to set the header on the specific
sheet........

Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
If wks.Range("A1") >= 1 Then
wks.PageSetup.RightHeader = "&""Arial Narrow,Regular""&8Page&Pof " & N
Else
wks.PageSetup.RightHeader = "" '< Runs out back door hugs a few
trees>
End If
Next



--
Cheers
Nigel



Nigel said:
Put a loop around the header set up as follows..........

Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
If Range("A1") >= 1 Then
ActiveSheet.PageSetup.RightHeader = "&""Arial Narrow,Regular""&8Page&P
of " & N
Else
ActiveSheet.PageSetup.RightHeader = "" '< Runs out back door hugs
a few trees>
End If
Next

---
Cheers
Nigel

Private Sub Workbook_BeforePrint(Cancel As Boolean)
With ActiveWorkbook.Sheets
N = WorkSheets("Cover").Range("MyPages").Value
If Range("A1") >= 1 Then
ActiveSheet.PageSetup.RightHeader = "&""Arial
Narrow,Regular""&8Page
&P of " & N
Else
ActiveSheet.PageSetup.RightHeader = "" '< Runs out back door
hugs a few trees>
End If
End With
End Sub

Works but only changes heading on active sheet. I want to change the
header
on every sheet (5 or 9 depending).
I don't want to name the workbook as it may change. Path may change as
well.
Do I need loop statement? Quite happy I got this far.
The P is actually [P] - [PAGES], is there a way to easily display these
hidden characters?

I found "VB help, with, control flow keyword summary", seems to help. Any
other suggested sources?
Thanks Lou
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top