Hello All,
Currently I am trying to write a macro for my job where a user form box pops up and with check boxes the user can select which pages to print, and prints them to an 11x17 page, landscape, while fitting the page to 1 sheet of paper. With consistent "block if without end if" errors,
So far I have been kind of successful? (yes I know all the print ranges are the same, Just hadnt changed them yet)
The main challenge is that all 4 "pages" are on the same excel sheet, and need to stay that way. My code is intended to go through, and, if the check box is selected, set the print area to the given range and print out that page. Ideally with a printout preview but that would not work for me.
I was able to get a single sheet to work and print properly, but now once adding in the buttons for the next 3 sheets, it no longer is working for me.
Fair warning I am new to VBA and just getting into it, so there is 100% dumb mistakes and over-complicated commands,
If anyone has any ideas It would be greatly appreciated!
(Not sure how y'all put the little boxes with code So i will just post it below)
Private Sub CB1_Click()
'
' codegrab Macro
'
With ActiveSheet.PageSetup
ActiveSheet.PageSetup.PrintArea = ("$A$1:$AM$59")
With ActiveSheet.PageSetup
.LeftHeader = "0.25"
.CenterHeader = "0.25"
.RightHeader = "0.25"
.LeftFooter = "0.25"
.CenterFooter = "0.25"
.RightFooter = "0.25"
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.25)
.BottomMargin = Application.InchesToPoints(0.25)
.HeaderMargin = Application.InchesToPoints(0.25)
.FooterMargin = Application.InchesToPoints(0.25)
.PrintHeadings = False
.PrintGridlines = False
.PrintQuality = 600
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperTabloid
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.Application.PrintCommunication = True
End With
ActiveWindow.PrintOut copies = 1
End Sub
Private Sub CB2_click()
With ActiveSheet.PageSetup
ActiveSheet.PageSetup.PrintArea = ("$A$60:$AM$118")
With ActiveSheet.PageSetup
.LeftHeader = "0.25"
.CenterHeader = "0.25"
.RightHeader = "0.25"
.LeftFooter = "0.25"
.CenterFooter = "0.25"
.RightFooter = "0.25"
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.25)
.BottomMargin = Application.InchesToPoints(0.25)
.HeaderMargin = Application.InchesToPoints(0.25)
.FooterMargin = Application.InchesToPoints(0.25)
.PrintHeadings = False
.PrintGridlines = False
.PrintQuality = 600
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperTabloid
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.Application.PrintCommunication = True
End With
ActiveWindow.PrintOut copies = 1
End Sub
Private Sub CB3_click()
With ActiveSheet.PageSetup
ActiveSheet.PageSetup.PrintArea = ("$AN$1:$CA$59")
With ActiveSheet.PageSetup
.LeftHeader = "0.25"
.CenterHeader = "0.25"
.RightHeader = "0.25"
.LeftFooter = "0.25"
.CenterFooter = "0.25"
.RightFooter = "0.25"
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.25)
.BottomMargin = Application.InchesToPoints(0.25)
.HeaderMargin = Application.InchesToPoints(0.25)
.FooterMargin = Application.InchesToPoints(0.25)
.PrintHeadings = False
.PrintGridlines = False
.PrintQuality = 600
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperTabloid
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.Application.PrintCommunication = True
End With
ActiveWindow.SelectedSheets.PrintOut copies = 1
End Sub
Private Sub CB4_click()
With ActiveSheet.PageSetup
ActiveSheet.PageSetup.PrintArea = ("$AN$60:$CA$118")
With ActiveSheet.PageSetup
.LeftHeader = "0.25"
.CenterHeader = "0.25"
.RightHeader = "0.25"
.LeftFooter = "0.25"
.CenterFooter = "0.25"
.RightFooter = "0.25"
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.25)
.BottomMargin = Application.InchesToPoints(0.25)
.HeaderMargin = Application.InchesToPoints(0.25)
.FooterMargin = Application.InchesToPoints(0.25)
.PrintHeadings = False
.PrintGridlines = False
.PrintQuality = 600
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperTabloid
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
End With
ActiveWindow.SelectedSheets.PrintOut copies = 1
End Sub
Bookmarks