none
Select multiple page number from multiple sheet RRS feed

  • Question

  • Hello
    I want a macro for the following command:

    Sheet1 Page 1 to 5
    Sheet2 Page 4 to 8
    Converts to a PDF file

    Of course, this code only works for a single sheet
     Sheets("Sheet1").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
           ("D:\....\".pdf"), Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, From:=1, To:=11

    Saturday, January 20, 2018 3:05 PM

All replies

  • Hi Kaprio,

    Could you explain more details about what you want to do?
    I can hardly understand especially:
        Sheet1 Page 1 to 5
        Sheet2 Page 4 to 8
       Converts to a PDF file

    Regards,


    Ashidacchi

    Sunday, January 21, 2018 12:58 AM
  • Hi Ashidacchi

    The following code converts pages 1 - 11  of ("Sheet1")to PDF
    My problem is that I have pages in
    ("Sheet2")
    And I want convert all  pages in a  one PDF file.

    ......

    sub to_pdf()

    Sheets("Sheet1").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
           ("D:\folder1\".pdf"), Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, From:=1, To:=11end sub

    Regards,

    Sunday, January 21, 2018 6:18 AM
  • Dear Ashidacchi

    In addition
    You have not had a solution to any of my questions
    " Just want an explanation "
    It's also for clear and clear questions

    Interestingly, the very same responses in this forum give you a rating !!!!

    Regards,


    • Edited by Kaprio Sunday, January 21, 2018 8:42 AM
    Sunday, January 21, 2018 8:41 AM
  • Hi Caprio,

    If you want to provide any answers, you will know how you do not have information for answeing his/her question. So, I ask some question to confirm what is the issue.

    Regards,


    Ashidacchi

    Sunday, January 21, 2018 11:24 AM
  • Hi kapriano,

    Filename:=("D:\folder1\".pdf")  is a wrong code.
    Please correct your code like this:
    Sub to_pdf()
        Sheets("Sheet1").ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=("D:\folder1\sheet1.pdf"), _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        From:=1, To:=11
    End Sub
    Regards,

    Ashidacchi

    Monday, January 22, 2018 1:31 AM
  • Hello Kaprio,

    As far as I know, you could export multiple sheet into one pdf. However, you could not specific page in this situation.

    As workaround, I would suggest you specific the page range as print area and then export the print area to pdf.

    For instance, in my test, page 1 to 5 in sheet1 is A1:I250, page 4 to 8 in sheet2 is A201:I400.

    So the code is

    Sub Test()
    Sheets("Sheet1").PageSetup.PrintArea = "A1:I250"
    Sheets("Sheet2").PageSetup.PrintArea = "A201:I400"
    ThisWorkbook.Sheets(Array("Sheet1", "Sheet2")).Select
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "C:\Users\v-guaxu\Desktop\TestFolder\test.pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, _
         IgnorePrintAreas:=False, OpenAfterPublish:=True
    End Sub

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Kaprio Monday, January 22, 2018 4:14 PM
    • Unmarked as answer by Kaprio Monday, January 22, 2018 9:35 PM
    Monday, January 22, 2018 6:22 AM
  • Thank you Terry

    I just do not know why it does not ordring work

    First, bring sheet2 . Next sheet1
    I even changed their place in the code, but did not

    How can I tell sheet1 is first ?
    Regards

    • Edited by Kaprio Monday, January 22, 2018 10:43 PM
    Monday, January 22, 2018 4:14 PM
  • Hello Kaprio,

    You have to change their sheet order in the workbook.

    Here is the example.

    Sub Test()
    Sheets("Sheet1").PageSetup.PrintArea = "A1:I250"
    Sheets("Sheet2").PageSetup.PrintArea = "A201:I400"
    Sheets("Sheet2").Move Before:=Sheets("Sheet1")
    ThisWorkbook.Sheets(Array("Sheet1", "Sheet2")).Select
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "C:\Users\v-guaxu\Desktop\TestFolder\test.pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, _
         IgnorePrintAreas:=False, OpenAfterPublish:=True
    End Sub

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by kapriano Wednesday, January 24, 2018 3:09 PM
    • Unproposed as answer by kapriano Wednesday, February 14, 2018 12:01 AM
    Tuesday, January 23, 2018 5:49 AM
  • Thank you Terry Regards
    • Proposed as answer by kapriano Wednesday, January 24, 2018 3:09 PM
    • Unproposed as answer by kapriano Wednesday, January 24, 2018 3:09 PM
    Wednesday, January 24, 2018 3:09 PM
  • Hello kaprio,

    Has your original issue been resolved? If it has, I would suggest you mark the helpful reply as answer  to close this thread. If not, please feel free to let us know your current issue.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 25, 2018 1:20 AM
  • HiThanks to all loved friends

    Sorry for the delay in the thanks and the answer
    Terry macro works fine
    But I do not know why when converting to PDF, the Excel window jumps to the other sheets?

    Of course, at the beginning and end of the macro, I use the following code

    sub main()

    Dim ActWks As Worksheet Set ActWks = ActiveSheet Application.ScreenUpdating = False call macro1

    call macro2 ActWks.Activate Application.ScreenUpdating = True Set ActWks = Nothing

    end sub

    Another thing is that after each print PDF, the printed sheets are grouped together !!!
    At the top of the Excel page next to the project name is the (group)!
    This is very dangerous because with any change in a sheet
    Other sheets also change
    !!

    Of course my project is over
    And now I'm working with just one sheet
    I would not have had this problem if I could compile my Excel project into a exe file.

    I wish I was a little professional, like you


    Best Regards,




    • Edited by kapriano Sunday, February 11, 2018 11:36 PM
    Sunday, February 11, 2018 7:41 AM
  • Hi Kapriano,

    Usually one thread will discuss one specific question, if the original question was resolved, I suggest you can mark that reply which answers your original ask, then open some other questions separately and we will continue to work on them to help you resolve them as soon as possible.

    Thanks,

    Jie


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 19, 2018 6:10 AM