View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Omit header from first page without embedding header in code

Hi ibvalentine,

The reasons it does not work is because you are saving the null ("") into
the headers again instead putting the saved value back into the headers and
also you cannot use the same variable sHeader to save 3 different variables.
You need one each.

Try this and see how it goes.

Sub NoFirstPageHeader_AllSheets()
Dim wsSheet As Worksheet
Dim strLeft As String
Dim strRight As String
Dim strCenter As String

For Each wsSheet In Worksheets
With wsSheet
strLeft = .PageSetup.leftHeader
.PageSetup.leftHeader = ""
strCenter = .PageSetup.CenterHeader
.PageSetup.CenterHeader = ""
strRight = .PageSetup.rightHeader
.PageSetup.rightHeader = ""
.PrintOut From:=1, To:=1
.PageSetup.leftHeader = strLeft
.PageSetup.CenterHeader = strCenter
.PageSetup.rightHeader = strRight
.PrintOut From:=2
End With
Next wsSheet
End Sub

Regards,

OssieMac

"ibvalentine" wrote:

I want to print a multi-page worksheet omitting the header on the first page.
However, I also want to create a macro to do this without embedding the
header info in the code. I do not know VBA programming, but I have been
reading some web sites and playing around with it.

Here's a solution that I thought would work (maybe it just needs some
tweaking):

Sub NoFirstPageHeader_AllSheets()
Dim wsSheet As Worksheet
Dim sHeader As String
For Each wsSheet In Worksheets
With wsSheet
sHeader = .PageSetup.LeftHeader
.PageSetup.LeftHeader = ""
sHeader = .PageSetup.CenterHeader
.PageSetup.CenterHeader = ""
sHeader = .PageSetup.RightHeader
.PageSetup.RightHeader = ""
.PrintOut From:=1, To:=1
sHeader = .PageSetup.LeftHeader
sHeader = .CenterHeader
sHeader = .RightHeader
.PrintOut From:=2
End With
Next wsSheet
End Sub

The problem is that this code deletes my header entirely instead of what I
intended it to do (omit the header on the first page). I tried to replace
"PageSetup" with "Print" but that, of course, did not work. I am surprised
that doing a simple thing like omitting the header on the first page is such
a big deal.

I have come up with a few workarounds, but if anyone knows of a macro that
can do what I described, please let me know. Again, the sticky part is that I
want this to work in any workbook with different page headers.

Thanks!