Home > front end >  VBA code for Print to PDF (print pages 1 to 3 only)
VBA code for Print to PDF (print pages 1 to 3 only)

Time:12-08

I have the below code, and I am here to ask what I would need to add to the code to print pages 1 to 3 only?

Sub PrintVisa()

Dim invoiceRng As Range
Dim pdfile As String
'Setting range to be printed
Set invoiceRng = Range("C7:L175")
pdfile = " Seabourn_Visa_Letter"
invoiceRng.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=pdfile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=True, _
OpenAfterPublish:=True

CodePudding user response:

Please, try the next code:

Sub ExportFirstThreeSheets()
  Dim FileName As String
  FileName = ThisWorkbook.Path & "\MyThreeSheets.pdf"
   Sheets(Array(1, 2, 3)).copy 'it creates a new workbook containing the first three sheets
    With ActiveWorkbook
        .ExportAsFixedFormat xlTypePDF, FileName, , , , , , True
        .Close False
    End With
End Sub
  • Related