簡體   English   中英

VBA 打印到 PDF 的代碼(僅打印第 1 至 3 頁)

[英]VBA code for Print to PDF (print pages 1 to 3 only)

我有以下代碼,我在這里問我需要添加到代碼中以僅打印第 1 到 3 頁?

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

請嘗試下一個代碼:

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

ExportAsFixedFormat 具有內置的頁面范圍。見下文:

Sheet5.ExportAsFixedFormat 類型:=xlTypePDF,文件名:=“YouFileName.pdf”,質量:=xlQualityStandard,IncludeDocProperties:=False,IgnorePrintAreas:=False, From:=1,To:=3, OpenAfterPublish:=True

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM