Djblois
05-11-2007, 06:07 AM
I have found a lot of ways to reduce the size of my code. I am using this code to set the pagesetup:
PagSetPrintHeading "&A", "Atalanta", fnCalcTime(workingBook, 2)
Sub PagSetPrintHeading(ByRef sgCenterHeaderText As String, _
Optional ByRef sgLeftHeaderText As String, Optional ByRef sgRightHeaderText As String, _
Optional ByRef lgZoom As Long, Optional ByRef sgOrientation As String)
With ActiveSheet.PageSetup
On Error Resume Next
.LeftHeader = "&""Arial,Bold""&12" & sgLeftHeaderText
.CenterHeader = "&""Arial,Bold""&14" & sgCenterHeaderText
On Error Resume Next
.RightHeader = "&""Arial,Bold""&12" & sgRightHeaderText
On Error Resume Next
.Zoom = lgZoom
On Error Resume Next
.Orientation = sgOrientation
End With
End Sub
and finally the function:
Function fnCalcTime(shtLookup As Worksheet, lgColumn As Long)
With Application.WorksheetFunction
fnCalcTime = .text(.Min(shtLookup.Columns(lgColumn)), "mm\\dd\\yy") & " - " & .text(.Max(shtLookup.Columns(lgColumn)), _
"mm\\dd\\yy")
End With
End Function
I have no problem with errors. The problem is the right header doesn't print, instead it prints almost like it is a watermark, not a right header.
PagSetPrintHeading "&A", "Atalanta", fnCalcTime(workingBook, 2)
Sub PagSetPrintHeading(ByRef sgCenterHeaderText As String, _
Optional ByRef sgLeftHeaderText As String, Optional ByRef sgRightHeaderText As String, _
Optional ByRef lgZoom As Long, Optional ByRef sgOrientation As String)
With ActiveSheet.PageSetup
On Error Resume Next
.LeftHeader = "&""Arial,Bold""&12" & sgLeftHeaderText
.CenterHeader = "&""Arial,Bold""&14" & sgCenterHeaderText
On Error Resume Next
.RightHeader = "&""Arial,Bold""&12" & sgRightHeaderText
On Error Resume Next
.Zoom = lgZoom
On Error Resume Next
.Orientation = sgOrientation
End With
End Sub
and finally the function:
Function fnCalcTime(shtLookup As Worksheet, lgColumn As Long)
With Application.WorksheetFunction
fnCalcTime = .text(.Min(shtLookup.Columns(lgColumn)), "mm\\dd\\yy") & " - " & .text(.Max(shtLookup.Columns(lgColumn)), _
"mm\\dd\\yy")
End With
End Function
I have no problem with errors. The problem is the right header doesn't print, instead it prints almost like it is a watermark, not a right header.