Results 1 to 2 of 2

Trying to make a macro to set and print areas based on checkbox inputs.

Threaded View

  1. #1
    Registered User
    Join Date
    03-28-2023
    Location
    Ontario, Canda
    MS-Off Ver
    2022
    Posts
    1

    Unhappy Trying to make a macro to set and print areas based on checkbox inputs.

    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
    Last edited by XRYXS; 03-28-2023 at 02:52 PM. Reason: Updated code.. still getting 'expected end with'

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Print Worksheet/Areas With Checked CheckBox Control
    By casom in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-01-2020, 12:38 PM
  2. Print two print areas on one via a macro, for a loop
    By Mathpi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-19-2018, 02:08 PM
  3. [SOLVED] Define 3 print areas, make a PDF, open and attach the PDF to Microsoft Outlook.
    By gnaske in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-07-2017, 04:03 AM
  4. [SOLVED] Loop through checkbox and inputs data based on which is checked
    By joe8904 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-14-2016, 09:51 AM
  5. Macro to print multiple print areas on one page.
    By morangeman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-23-2015, 12:13 PM
  6. Help! Set Ranges Based on Print Areas in VBA?
    By amanda12345 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2013, 05:52 PM
  7. Macro need to change print areas based on Populated rows
    By awaring in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2010, 02:01 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1