Printing Multiple Sheets into One PDF

3link

Board Regular
Joined
Oct 15, 2010
Messages
145
I would like to print two sheets into one PDF document. The first sheet is an "invoice" sheet that contains the client's information and the amount I'm billing them. The second sheet is a "support" document that supports the amount on the "invoice" sheet. The support sheet is basically a largetable with all the support for all of my invoices. Before attempting to print, I apply a filter to that table so that only the "support" relevant to the client I am billing will appear in the "support" sheet. ( The code I am using to apply that filter appears to work fine.)

Here is the code that I put together to print the two sheets into one PDF. While this code technically prints both sheets into a single PDF document, I the output is problematic for two reasons. First, it seems to ignore my print areas. I have a defined print area in the "Invoices" sheet yet the output of my code below prints the entire "invoices" sheet, including the area outside of the print area. Second, for some reason the output prints multiple blank pages between the "invoice" sheet and the "support" sheet, and a few blank pages after the "support sheet." Any idea what I'm doing wrong here?

VBA Code:
Sub Button16_Click()
 Sheets("Invoice Cover").Activate
   ActiveSheet.UsedRange.Select
   Sheets("Support").Activate
   ActiveSheet.UsedRange.Select
   ThisWorkbook.Sheets(Array("Invoice Cover", "Support")).Select
   Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
      "C:\Users\[ME]Desktop\test", Quality:=xlQualityStandard, _
      IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
      True
End Sub

Unrelated to the issues I'm having, I am wondering if there is any way to name the PDF file based on a cell value in the "invoices" sheet. I tried a few codes I found on google but was ultimately unsuccessful. I would greatly appreciate any assistance.
 
I figured it out! In case anyone is curious, this worked for me.

VBA Code:
Dim StringrngRange        As String
Dim StringrngRange2        As String
StringrngRange = Worksheets("Invoice Cover").Range("A1").Value 'contains text I want to include in the title of the PDF
StringrngRange2 = Worksheets("Invoice Cover").Range("C18").Value 'also contains text I want to include in the title of the PDF
    Sheets(Array("Invoice cover", "Support")).Select
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "C:\Users\Desktop[me]\" & StringrngRange & ", " & StringrngRange2 & ".pdf", _
        Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas _
        :=False, OpenAfterPublish:=False
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top