+ Reply to Thread
Results 1 to 8 of 8

Print 2 Excel sheets to same PDF File

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-25-2012
    Location
    Edmonton, Alberta
    MS-Off Ver
    2010
    Posts
    146

    Print 2 Excel sheets to same PDF File

    Hi,
    I need to print 2 excel sheets into the same PDF File (I use Primo PDF if that matters).
    Currently the way it works is that it selects sheet then prints it, then call another macro and then selects that sheet and prints it.
    But when it does that it is basically creating 2 separate PDF Files which I don't want.
    Also I don't need to have the print dialog box come up twice.
    Any Ideas?

    Sub PrintDaily()
    '
    ' PrintDaily Macro
    '
    
    '
        Sheets("Daily (1)").Select
        Sheets("Dont Unhide Daily Report").Visible = True
        Sheets("Dont Unhide Daily Report").Select
        Application.Dialogs(xlDialogPrinterSetup).Show
        ActiveWindow.SelectedSheets.PrintOut copies:=1, Collate:=True, _
            IgnorePrintAreas:=False
        Sheets("Dont Unhide Daily Report").Select
        ActiveWindow.SelectedSheets.Visible = False
        ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
        Sheets("Daily (1)").Select
        Call PrintCosts
        Range("F4").Select
    End Sub
    Sub PrintCosts()
    '
    ' PrintCosts Macro
    '
    
    '
        Sheets("Costs").Select
        Sheets("Don't Unhide Costs Report").Visible = True
        Sheets("Don't Unhide Costs Report").Select
         Application.Dialogs(xlDialogPrinterSetup).Show
         ActiveWindow.SelectedSheets.PrintOut copies:=1, Collate:=True, _
            IgnorePrintAreas:=False
        Sheets("Don't Unhide Costs Report").Select
        ActiveWindow.SelectedSheets.Visible = False
        Sheets("Costs").Select
        ActiveWindow.SmallScroll Down:=-6
        Range("D40").Select
    End Sub

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,932

    Re: Print 2 Excel sheets to same PDF File

    Try this, but I didn't create a file to test it. It would be easier to have yours.

    Sub PrintBoth()
        
        Dim SheetNames() As String
        SheetNames = Array("Dont Unhide Daily Report", "Don't Unhide Costs Report")
        
        Sheets(SheetNames).Visible = True
        Sheets(SheetNames).Select
        
        Application.Dialogs(xlDialogPrinterSetup).Show
        ActiveWindow.SelectedSheets.PrintOut copies:=1, Collate:=True, _
            IgnorePrintAreas:=False
            
        Sheets(SheetNames).Visible = False
        
        Sheets("Costs").Select
        ActiveWindow.SmallScroll Down:=-6
        Sheets("Costs").Range("D40").Select
        
    End Sub
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    11-25-2012
    Location
    Edmonton, Alberta
    MS-Off Ver
    2010
    Posts
    146

    Re: Print 2 Excel sheets to same PDF File

    Hi 6StringJazzer,
    Thanks! I seem to be getting an error in
    SheetNames = Array("Dont Unhide Daily Report", "Don't Unhide Costs Report")
    line when I try it.
    My file is to large to upload

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,932

    Re: Print 2 Excel sheets to same PDF File

    OK, this one was tested in a mock-up.

    Sub PrintBoth()
        
        Dim SheetNames As Variant
        SheetNames = Array("Dont Unhide Daily Report", "Don't Unhide Costs Report")
        
        Sheets("Dont Unhide Daily Report").Visible = True
        Sheets("Don't Unhide Costs Report").Visible = True
        
        Sheets(SheetNames).Select
        
        Application.Dialogs(xlDialogPrinterSetup).Show
        ActiveWindow.SelectedSheets.PrintOut copies:=1, Collate:=True, _
            IgnorePrintAreas:=False
            
        Sheets("Dont Unhide Daily Report").Visible = False
        Sheets("Don't Unhide Costs Report").Visible = False
        
        Sheets("Costs").Select
        ActiveWindow.SmallScroll Down:=-6
        Sheets("Costs").Range("D40").Select
        
    End Sub

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,932

    Re: Print 2 Excel sheets to same PDF File

    Modify the code as shown. You will have to specify the location where you want it to be saved as shown. If you want to allow the user to specify anything they want then maybe the original version is your best bet.

    Sub PrintBoth()
        
        Dim SheetNames As Variant
        SheetNames = Array("Dont Unhide Daily Report", "Don't Unhide Costs Report")
        
        Sheets("Dont Unhide Daily Report").Visible = True
        Sheets("Don't Unhide Costs Report").Visible = True
        
        Sheets(SheetNames).Select
        
        ActiveSheet.ExportAsFixedFormat _
          Type:=xlTypePDF, _
          Filename:="YOUR FILE PATH GOES HERE" & ".pdf", _
          Quality:=xlQualityStandard, _
          IncludeDocProperties:=True, _
          IgnorePrintAreas:=False, _
          OpenAfterPublish:=False
    
            
        Sheets("Dont Unhide Daily Report").Visible = False
        Sheets("Don't Unhide Costs Report").Visible = False
        
        Sheets("Costs").Select
        ActiveWindow.SmallScroll Down:=-6
        Sheets("Costs").Range("D40").Select
        
    End Sub

  6. #6
    Forum Contributor
    Join Date
    11-25-2012
    Location
    Edmonton, Alberta
    MS-Off Ver
    2010
    Posts
    146

    Re: Print 2 Excel sheets to same PDF File

    Thanks, Sorry about late reply, but works good!

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,932

    Re: Print 2 Excel sheets to same PDF File

    This could also be exported directly to PDF natively in 2007+ without having to bring up the print dialog for the user and going through a third-party PDF writer. Do you need to go through the print dialog, or would you prefer to go direct to PDF?

  8. #8
    Forum Contributor
    Join Date
    11-25-2012
    Location
    Edmonton, Alberta
    MS-Off Ver
    2010
    Posts
    146

    Re: Print 2 Excel sheets to same PDF File

    Sure, what would that look like, may be easier...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Print 2 sheets to one PDF file
    By akderitend in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-24-2014, 08:31 AM
  2. Replies: 6
    Last Post: 05-03-2013, 09:52 AM
  3. [SOLVED] Schedule Excel to open file, print sheets, close file
    By tonychopra194 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-22-2012, 05:15 AM
  4. Print sheets to PDF when file opened?
    By Wabby in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-15-2010, 05:21 AM
  5. Replies: 2
    Last Post: 04-07-2005, 09:06 AM

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