VBA: Print page range

  • My need is not to reproduce any worksheet or sort anything, just to print the CUSTOMER ORDERS worksheet from the CUSTOM command button on the CONFIGURE worksheet. I need to have control of the number of pages to print off of the worksheet, from 1 to (n). The VBA Code I have now doesn’t print the CUSTOMER ORDERS worksheet, instead it comes back and prints the CONFIGURE worksheet.


    Kenneth

  • This might be more like it.

    The PDF files are saved in the same folder where your workbook is saved/stored.

    You have to put the code in a regular module and have a button on any sheet you want wherever you like on that sheet and assign this code to that button. BTW, I only use FormControl buttons. If you want it different, you have to change that part to suit your needs.

    Code should print from "CUSTOM ORDERS" sheet and it should print every page that is related to having a 1 (one) in column B in "CUST ORDERS" sheet.

    It is assumed that the pages are in order where you have that 1 (one) in that first sheet. PDF Files are saved in the folder where your excel workbook resides and are named by Company name. Change the PDF printing routine to Printout for regular printing if you want. I like to save in PDF format so I can go over the saved file to check if all is the way it should be without wasting any paper.

    If you just want to say, print the first n pages from the "CUSTOM ORDERS" sheet, that should be no problem.

    Try this out in the meantime.

    Happy Easter and Good Luck



  • Change these 2 lines

    Code
    ptp = Application.InputBox("How many pages do you want to print?", "Amount of pages to print. Valid numericals only", 1)
    For j = 1 To ptp

    to this single line if you want to go that route.

    Code
    For j = 1 To sh1.Range("B1").Value

    Re: "instead it comes back and prints the CONFIGURE worksheet."

    If you did not change anything in the code and your attachment is true to your original, not so when I tried it.

  • I thank you for the extra help, but I’ll have to say this is a little deeper than I anticipated, I’m not that savvy on modules, I usually just do VBA straight from command buttons or check boxes or list boxes. I understand some of it, but I’m lost within some of the code. I’m not even sure where/how to insert it in VBA. Sorry, I’m not too knowledgeable in all this. I thought maybe a simple fix to the command button I now have, would work. To make it go to the CUSTOMER ORDERS worksheet, ask for/confirm the number of pages to print, capture the worksheet pages and print and then return back to the CONFIGURE worksheet.


    Kenneth

  • Your friend should be google

    https://www.ablebits.com/offic…/add-run-vba-macro-excel/

    I guess that's why you're reluctant to change your workbook to a manageable workbook.

    In the meantime, read the article in the hyperlink, copy the code into a regular module and print the sheets by running the macro as suggested in the article.

    I've attached your workbook. Save it to a folder and remember the name of the folder. Open the workbook and click on the "Maybe C" button on the configure sheet.

    When it is finished, go to the folder where you saved this workbook and check the newly added PDF files.


    ORDERS by 312 kclarck.xlsm

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!