Hello,
I have a subroutine (see below) that works perfectly well in the "ThisWorkbook" module; however, when I place it in a worksheet module, I receive an "Method 'Select' of object'_Worksheet' failed" message. I expect there's an obvious reason that escapes me. For various reasons, I need to be able to run this subroutine (or one that accomplishes the same thing) in a worksheet. Any help would be much appreciated.
Sub ROICPrints()
On Error GoTo errcatch
With ThisWorkbook
'Remove page breaks & add page breaks
Sheets("ROIC").ResetAllPageBreaks
Sheets("ROIC").Rows(55).PageBreak = xlPageBreakManual
Sheets("ROIC").Rows(85).PageBreak = xlPageBreakManual
'PRINT FORMAT SUMMARY TAB
Sheets("ROIC").PageSetup.LeftHeader = "&B" & Range("Summary!K2") & " " & "ROIC Summary" & "&B"
Sheets("ROIC").PageSetup.CenterHeader = ""
Sheets("ROIC").PageSetup.RightHeader = ""
Sheets("ROIC").PageSetup.LeftFooter = "© " & Format(Now, "yyyy") & " Morningstar, Inc. All Rights Reserved."
Sheets("ROIC").PageSetup.CenterFooter = "Page " & "&P" & "/" & "&N"
Sheets("ROIC").PageSetup.RightFooter = Format(Now(), "mmmm dd yyyy")
Sheets("ROIC").PageSetup.LeftMargin = Application.InchesToPoints(0.75)
Sheets("ROIC").PageSetup.RightMargin = Application.InchesToPoints(0.75)
Sheets("ROIC").PageSetup.TopMargin = Application.InchesToPoints(1)
Sheets("ROIC").PageSetup.BottomMargin = Application.InchesToPoints(1)
Sheets("ROIC").PageSetup.HeaderMargin = Application.InchesToPoints(0.5)
Sheets("ROIC").PageSetup.FooterMargin = Application.InchesToPoints(0.5)
Sheets("ROIC").PageSetup.PrintTitleRows = "$1:$9"
Sheets("ROIC").PageSetup.PrintTitleColumns = ""
Sheets("ROIC").PageSetup.PrintArea = "$A$11:$T$54, $A$55:$T$84"
Sheets("ROIC").PageSetup.Orientation = xlPortrait
Sheets("ROIC").PageSetup.Zoom = 80
Sheets("ROIC").PageSetup.FitToPagesWide = 1
Sheets("ROIC").PageSetup.FitToPagesTall = 1
Sheets("ROIC").PageSetup.CenterHorizontally = True
Sheets("ROIC").PageSetup.CenterVertically = False
End With
ThisWorkbook.Worksheets("ROIC").PrintPreview
Exit Sub
errcatch:
MsgBox Err.Description
End Sub
I have a subroutine (see below) that works perfectly well in the "ThisWorkbook" module; however, when I place it in a worksheet module, I receive an "Method 'Select' of object'_Worksheet' failed" message. I expect there's an obvious reason that escapes me. For various reasons, I need to be able to run this subroutine (or one that accomplishes the same thing) in a worksheet. Any help would be much appreciated.
Sub ROICPrints()
On Error GoTo errcatch
With ThisWorkbook
'Remove page breaks & add page breaks
Sheets("ROIC").ResetAllPageBreaks
Sheets("ROIC").Rows(55).PageBreak = xlPageBreakManual
Sheets("ROIC").Rows(85).PageBreak = xlPageBreakManual
'PRINT FORMAT SUMMARY TAB
Sheets("ROIC").PageSetup.LeftHeader = "&B" & Range("Summary!K2") & " " & "ROIC Summary" & "&B"
Sheets("ROIC").PageSetup.CenterHeader = ""
Sheets("ROIC").PageSetup.RightHeader = ""
Sheets("ROIC").PageSetup.LeftFooter = "© " & Format(Now, "yyyy") & " Morningstar, Inc. All Rights Reserved."
Sheets("ROIC").PageSetup.CenterFooter = "Page " & "&P" & "/" & "&N"
Sheets("ROIC").PageSetup.RightFooter = Format(Now(), "mmmm dd yyyy")
Sheets("ROIC").PageSetup.LeftMargin = Application.InchesToPoints(0.75)
Sheets("ROIC").PageSetup.RightMargin = Application.InchesToPoints(0.75)
Sheets("ROIC").PageSetup.TopMargin = Application.InchesToPoints(1)
Sheets("ROIC").PageSetup.BottomMargin = Application.InchesToPoints(1)
Sheets("ROIC").PageSetup.HeaderMargin = Application.InchesToPoints(0.5)
Sheets("ROIC").PageSetup.FooterMargin = Application.InchesToPoints(0.5)
Sheets("ROIC").PageSetup.PrintTitleRows = "$1:$9"
Sheets("ROIC").PageSetup.PrintTitleColumns = ""
Sheets("ROIC").PageSetup.PrintArea = "$A$11:$T$54, $A$55:$T$84"
Sheets("ROIC").PageSetup.Orientation = xlPortrait
Sheets("ROIC").PageSetup.Zoom = 80
Sheets("ROIC").PageSetup.FitToPagesWide = 1
Sheets("ROIC").PageSetup.FitToPagesTall = 1
Sheets("ROIC").PageSetup.CenterHorizontally = True
Sheets("ROIC").PageSetup.CenterVertically = False
End With
ThisWorkbook.Worksheets("ROIC").PrintPreview
Exit Sub
errcatch:
MsgBox Err.Description
End Sub