用于打印为PDF的VBA代码(仅打印第1页至第3页)



我有下面的代码,我在这里问我需要在代码中添加什么才能只打印第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

ExportAsFixedFormat内置了一个页面范围。请参阅以下内容:

表5.ExportAsFixedFormat类型:=xlTypePDF,文件名:="YouFileName.pdf";,质量:=xlQualityStandard,IncludeDocProperties:=False,IgnorePrintAreas:=False,发件人:=1,收件人:=3,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

最新更新