1st page only Headers & Footers

E

Etijian

I would not be suprised at all to discover that someone has already
addressed this, however, I've been digging around for several hours and
haven't found it yet. :)

I am attempting to modify an Excel workbook so that the center header
prints only on the first page and the center footer only prints on the
first page. Both the header and footer consist only of a graphic,
nothing else. I need it to print only on the 1st page whether I'm
printing just the first page of one sheet, or a couple of pages of one
sheet, or the entire workbook. I have found some code online and from
friends, but it never seems to work correctly. Either that, or I'm
pasting it in incorrectly. I've been fighting with this for weeks,
please help me! :eek:

Thanks in advance -

E
 
E

Etijian

I do realize that it requires VB coding, and I have made a littl
progress since my last post. First, I have determined that I don't nee
to be able to print only specific pages, but I do need to print just
currently active worksheet. I've found some sample code for that, bu
it still doesn't seem to limit it only to the active sheet. The cod
that I'm pasting below is what I have right now. When someone click
the Print button it prints every worksheet in the workbook, but it doe
do the headers and footers correctly. The only thing I need to fix now
is to make it print only the currently active worksheet, instead of th
entire workbook. Here is the code:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim wsSheet As Worksheet
Dim sFooter As String
Dim sHeader As String
Cancel = False
Application.EnableEvents = False
For Each wsSheet In ActiveWindow.SelectedSheets
With wsSheet
If .Name = "My Sheet" Then
sFooter = .PageSetup.CenterFooter
sHeader = .PageSetup.CenterHeader
.PrintOut From:=1, To:=1
.PageSetup.CenterFooter = ""
.PageSetup.CenterHeader = ""
.PrintOut From:=2
.PageSetup.CenterFooter = sFooter
.PageSetup.CenterHeader = sHeader
Else
.PrintOut
End If
End With
Next wsSheet
Application.EnableEvents = True
End Su
 
R

Ron de Bruin

Try this for the activesheet only

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim wsSheet As Worksheet
Dim sFooter As String
Dim sHeader As String
Cancel = True
Application.EnableEvents = False
With ActiveSheet
sFooter = .PageSetup.CenterFooter
sHeader = .PageSetup.CenterHeader
PrintOut From:=1, To:=1
.PageSetup.CenterFooter = ""
.PageSetup.CenterHeader = ""
.PrintOut From:=2
.PageSetup.CenterFooter = sFooter
.PageSetup.CenterHeader = sHeader
End With
Application.EnableEvents = True
End Sub
 

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