+ Reply to Thread
Results 1 to 7 of 7

Put two chosen ranges on two different pages of one PDF document

Hybrid View

  1. #1
    Registered User
    Join Date
    01-10-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2010
    Posts
    26

    Put two chosen ranges on two different pages of one PDF document

    Dear All,

    Below you can find the code that I've written out in order to get a PDF copy of a chosen range from my excel worksheet. Could anyone tell me how they would adjust the code so that instead of having one single page with the two ranges, I could have 1 range on the first page of a PDF and the second range on the second page of that same PDF. (i.e. the PDF would have 2 pages with one range on each page.)
    The execution is made via a command button (Button13_Click)
    The two ranges would go from range1(A1:K77) and range2(A78:K196)


    Sub Button13_Click()
    
        Dim path As String
        Dim objShell As Object, objFolder As Object, oFolderItem As Object
        Dim fileName, message, title, defaultValue As String
        Dim myValue As Object
        
        Set objShell = CreateObject("Shell.Application")
       
       ' Met le text que tu veux à la place de Desired file location
       Set objFolder = objShell.BrowseForFolder(&H0&, "Desired file location", &H1&)
       
       If Not (objFolder Is Nothing) Then
           path = objFolder.Self.path
           
           
           message = "File name"       ' Set message text
           title = "File name"         ' Set title text
           fileName = "Export"     ' Set default value.
           
           
           fileName = InputBox(message, title, defaultValue)
           ' If user has clicked Cancel, set myValue to defaultValue
           If fileName = "" Then
               fileName = defaultValue
           End If
           
           fileName = path & "\" & fileName & ".pdf"
           Sheets("Report").Range("A1:K196").ExportAsFixedFormat Type:=xlTypePDF, fileName:=fileName _
               , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
               :=False, OpenAfterPublish:=True
       End If
            
        Range("L169").Select
        ActiveWindow.SmallScroll Down:=-168
        Application.WindowState = xlMinimized
    End Sub
    Thank you for your help!

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Put two chosen ranges on two different pages of one PDF document

    Hi bobby.bobby

    Try inserting a Page Break in the Worksheet at A78.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    01-10-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Put two chosen ranges on two different pages of one PDF document

    Hey Jaslake,

    Thanks for replying. Ideally I would want to do it through VBA coding, is there really no other way of doing it through coding?

    Thanks again.

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Put two chosen ranges on two different pages of one PDF document

    Hi bobby.bobby

    Did manually inserting a Page Break in the Worksheet at A78 work?

    If so, insert a Page Break in the Worksheet at A78 WITH Code.

  5. #5
    Registered User
    Join Date
    01-10-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Put two chosen ranges on two different pages of one PDF document

    something like this, no?

    ActiveSheet.HPageBreaks.Add Before:=Range("A77")

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Put two chosen ranges on two different pages of one PDF document

    Hi bobby.bobby

    Did this work???
    ActiveSheet.HPageBreaks.Add Before:=Range("A77")
    If not I'll be happy to look at it...please post your Workbook.

  7. #7
    Registered User
    Join Date
    01-10-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Put two chosen ranges on two different pages of one PDF document

    Hey Jaslake,

    In the code written above, where would you include the VBA Coding to create the Page Break?

    I'm struggling to see where it would ideally be placed

    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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