【问题标题】:Excell VBA export some worksheets to PDF with ExportAsFixedFormat in a specified orderExcel VBA 以指定的顺序使用 ExportAsFixedFormat 将一些工作表导出为 PDF
【发布时间】:2014-03-05 02:14:45
【问题描述】:

我正在尝试在 Excel 中创建一个由 TitleSheet 和 ReportSheet 组成的 PDF 报告。当我选择我需要的两张表并使用 ExportAsFixedFormat 生成 PDF 时,我似乎无法控制将这些表添加到文档中的顺序。截至目前,TitleSheet 最终位于 ReportSheet 的底部......不是很有帮助。

这是我的相关代码和一些我尝试但不起作用的 cmet。

    Dim FilePath As String
FilePath = Application.GetSaveAsFilename(ReportSheet.Name & ".PDF", "PDF(*.pdf),*.pdf*", 1, "Save As PDF File")
If FilePath = "False" Then Exit Sub


TitleSheet.Select 'so it's the first in the DPF report, no worky
Dim PrintSheets(1) As Variant

PrintSheets(0) = TitleSheet.Name 'changed index order, no worky
PrintSheets(1) = ReportSheet.Name
Sheets(PrintSheets).Select 'select both sheets so they both print

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    FilePath, Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, _
    OpenAfterPublish:=True
ReportSheet.Activate 'select this sheet so it's visible at the end

我寻找了其他一些答案 (Exporting multiple pages to PDF in a specific order),但还没有雪茄。我在 TitlePage 和 ReportPage 之间有不同的列宽,所以我不想经历合并它们的麻烦。我也不能使用第 3 方 PDF 创建器,因为大多数用户在他们的机器上没有安装任何其他软件的管理员权限。

【问题讨论】:

    标签: vba pdf pdf-generation


    【解决方案1】:

    经过大量搜索和测试,我发现 ExportAsFixedFormat 根据选项卡/索引顺序导出工作表。这意味着我需要在 TitleSheet 之后使用这行代码对 ReportSheet 进行索引:

    ReportSheet.Move after:=TitleSheet
    

    维奥拉!特别感谢 Ken Puls:(http://www.excelguru.ca/forums/showthread.php?234-Reorder-pages-when-exporting-as-PDF&highlight=ExportAsFixedFormat)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-22
      • 2014-01-12
      • 1970-01-01
      • 2020-06-27
      • 2016-08-04
      • 1970-01-01
      • 1970-01-01
      • 2016-12-06
      相关资源
      最近更新 更多