Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用VBA从多个Excel工作表中的不同范围创建PDF_Vba_Excel_Pdf - Fatal编程技术网

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

使用VBA从多个Excel工作表中的不同范围创建PDF,vba,excel,pdf,Vba,Excel,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

我需要将几个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之外,当我选择ReportPage1时!A1:E30和ReportPage2!A1:F70,当我选择两张图纸时,它会将所选范围更改为ReportPage1!A1:E30和ReportPage2!A1:E30

有什么办法解决这个问题吗


任何帮助都将不胜感激。

好的,我解决了。如果我没有在特定页面上选择任何范围,它将自动获得每张页面的打印区域范围

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

而不是执行Selection.exportasfixedformat。您能否将其更改为application.exportasfixedFormat,然后使用“收件人”和“发件人”选择所需的页面?或工作簿。exportasfixedFormat…谢谢,但我相信这两种格式都不起作用。记住,我需要从每张纸上选择特定的区域。谢谢你,这个问题困扰了我好几个星期。