Option Explicit
Sub PageSetupEverySheetFaster()
' ---------------------------------------------------------------------------
' Add some document property info to the footers:
Dim szLastSaveTime As String
szLastSaveTime = ThisWorkbook.BuiltinDocumentProperties("Last Save Time")
Dim szHyperLink As String
szHyperLink = ThisWorkbook.BuiltinDocumentProperties("HyperLink Base")
' ---------------------------------------------------------------------------
' ---------------------------------------------------------------------------
' We use an old xlm macro to get the number of pages we will print from the
' the active sheet
Dim lPageNum As Long
lPageNum = Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
' ---------------------------------------------------------------------------
' ---------------------------------------------------------------------------
' Proceed with a basic setup: DO the first sheet only here:
With Worksheets(1).PageSetup
.LeftFooter = "Last Saved: " & _
Format(szLastSaveTime, "mm-dd-yy hh:mm:ss")
.RightFooter = szHyperLink
.RightHeader = "&D"
.LeftHeader = "Page &P of " & lPageNum
.Orientation = xlLandscape
.CenterHeader = "MAIN HEADER"
End With
' ---------------------------------------------------------------------------
' Select all worksheets at once: Faster than looping through!
Worksheets.Select
' ---------------------------------------------------------------------------
' Simulate key presses for "File > PageSetup > OK"
' This copies the PageSetup info to all the other sheets
SendKeys "%f", True
SendKeys "u"
SendKeys "{ENTER}", True
' ---------------------------------------------------------------------------
Worksheets(1).Select
End Sub
|