1

I have a VBA code for Excel to print quadruplicate copies on the default printer.

What I want is to save this quadruplicate as a single PDF file i.e all four sheets in a single continuous 4 pages PDF file.

The code is as below.

Sub PrintInvoiceQuadtriplicate()
    Dim i As Integer
    Dim VList As Variant

    VList = Array("ORIGINAL  FOR  RECIPIENT", "DUPLICATE  FOR  TRANSPORTER", "TRIPLICATE  FOR  SELLER", "EXTRA  COPY")
    For i = LBound(VList) To UBound(VList)
        Range("L1") = VList(i)
        ActiveSheet.PrintOut
    Next
End Sub 

Kindly let me know how to modify this code to get a single PDF file instead of separate pages.

waka
  • 3,362
  • 9
  • 35
  • 54
SYED
  • 11
  • 1
  • Possible duplicate. Following should give you enough to write your code: https://stackoverflow.com/questions/14404650/save-multiple-sheets-to-pdf – Zac Sep 15 '17 at 10:15
  • @SYED If my answer worked, please accept it by hitting the button below the up/down vote! – Teasel Oct 12 '17 at 08:41

1 Answers1

1

As said by Zac, possible duplicate with this post which has been answered.

Seems like you have to select your sheets before exporting as a PDF.

ThisWorkbook.Sheets(Array("Sheet1", "Sheet2")).Select

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    "C:\tempo.pdf", Quality:= xlQualityStandard, IncludeDocProperties:=True, _
     IgnorePrintAreas:=False, OpenAfterPublish:=True

Credit @Tim Williams for his answer.

Teasel
  • 1,330
  • 4
  • 18
  • 25
  • This solution does not work because in this solution the sheets are defined and are present in the workbook, whereas in my case the sheets are generated one by one by macro and then sent to the printer one after another. – SYED Oct 13 '17 at 17:04
  • @SYED What is the problem? Just use the name of each sheet instead of activesheet – Teasel Oct 13 '17 at 17:39
  • If I use Sheet name in place of Active sheet then also it will save in pdf as single sheets, what I need is I want all these sheet in one continuous pdf sheet with 4 pages. – SYED Oct 13 '17 at 18:42