Excel VBA 将选定的工作表导出为 PDF

Excel VBA 将选定的工作表导出为 PDF

问题描述:

我正在使用以下代码将选定的工作表从 Excel 2010 导出到单个 pdf 文件...

I'm using the following code to export selected sheets from Excel 2010 to a single pdf file...

ThisWorkbook.Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select

ActiveSheet.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:="C:	emp.pdf", _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=True

我的问题是它只导出第一张纸.有什么想法吗?

My problem is that it only exports the first sheet. Any ideas?

一旦你选择了一组工作表,你就可以使用选择

Once you have Selected a group of sheets, you can use Selection

考虑:

Sub luxation()
    ThisWorkbook.Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
    Selection.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:="C:TestFolder	emp.pdf", _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=True
End Sub

编辑#1:

进一步的测试表明,该技术取决于每个工作表上选择的单元格组.要获得全面的输出,请使用以下内容:

Further testing has reveled that this technique depends on the group of cells selected on each worksheet. To get a comprehensive output, use something like:

Sub Macro1()

   Sheets("Sheet1").Activate
   ActiveSheet.UsedRange.Select
   Sheets("Sheet2").Activate
   ActiveSheet.UsedRange.Select
   Sheets("Sheet3").Activate
   ActiveSheet.UsedRange.Select

   ThisWorkbook.Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
   Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
      "C:UsersJamesDesktoppdfmaker.pdf", Quality:=xlQualityStandard, _
      IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
      True
End Sub