Excell vba以指定顺序将一些工作表导出到PDF



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

这是我相关的代码,也是我尝试过的事情的一些评论。

    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

我寻找了其他一些答案(以特定顺序将多页导出到PDF),但还没有雪茄。我在标题页面和报告页之间有不同的列宽度,因此我不想经历合并这些的头痛。我也不能使用第三方PDF创建者,因为用户的Mojority在其机器上没有管理权以安装任何其他软件。

在大量搜索和测试之后,我发现基于选项卡/索引顺序的导出fortasfixedformat导出表。这意味着我需要在标题之后使用此代码索引报告表:

ReportSheet.Move after:=TitleSheet

中提琴!特别感谢Ken Puls :( http://www.excelguru.ca/forums/showthread.php?234-reorder-pages-when-exporting-asporting-as-pdf& highighlight; highighlight = exportasfixedformat)

最新更新