[英]Create PDF from different ranges in multiple Excel sheets with VBA
我需要将几个Excel工作表导出到一个PDF文件中。 我目前正在使用以下内容:
Sub CreatePDF()
Sheets("ReportPage1").Select
Range("Print_Area").Select
Sheets("ReportPage2").Select
Range("Print_Area").Select
Sheets("ReportPage3").Select
Range("Print_Area").Select
ThisWorkbook.Sheets(Array("ReportPage1", "ReportPage2", "ReportPage3")).Select
Selection.ExportAsFixedFormat _
Type:=xlTypePDF, _
FileName:="C:\temp\temp.pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
Sheets("ReportPage1").Select
Range("A1").Select
End Sub
问题是所有打印区域都不同。 所生成的PDF使用的是所有页面的ReportPage1打印区域的范围地址。
我在VBA之外的Excel本身中进行了尝试,例如,当我选择了ReportPage1!A1:E30和ReportPage2!A1:F70时,当我选择两个工作表时,它将选择的范围更改为ReportPage1!A1:E30和ReportPage2 A1:E30。
任何想法如何解决这个问题?
任何帮助都感激不尽。
好的,我解决了。 如果我没有在特定页面上选择任何范围,它将自动获取每张纸的Print_Area范围。
Sub CreatePDF()
ThisWorkbook.Sheets(Array("ReportPage1", "ReportPage2", "ReportPage3")).Select
Sheets("ReportPage1").Activate
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
FileName:="C:\temp\temp.pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
Sheets("ReportPage1").Select
Range("A1").Select
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.