使用VBA在多个Excel工作表中创build不同范围的PDF

我需要将多个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中所有页面的打印区域的范围地址。

我在Excel中自己尝试了,而不是在VBA中,当我select了ReportPage1!A1:E30和ReportPage2!A1:F70时,当我select这两个工作表时,它将把select的范围改为ReportPage1!A1:E30和ReportPage2 !A1:E30。

任何想法如何解决这个问题?

任何帮助都感激不尽。

好的,我解决了。 如果我没有select特定页面上的任何范围,它将自动获得每张纸的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