【问题标题】:PDF'ing Workbook - Page numbers algined to PDF instead of SheetPDF'ing 工作簿 - 以 PDF 代替工作表的页码
【发布时间】:2017-12-05 22:28:11
【问题描述】:

我有一个包含多张工作表的工作簿。有些工作表超过 1 页,所以我在页脚 Page &[Page] of &[Pages] 中有以下内容以显示每张工作表中的页数。

然后我使用下面的代码将它们 PDF:

Sub PDFSheets()
    Dim ans As Variant
    Dim fPath As String
    Dim Team As String
    ans = MsgBox("Please ensure the sheets you would like to PDF are visible before running this macro. Files will be saved to your Desktop." & Chr(10) & Chr(10) & "Do you wish to continue?", vbYesNo + vbInformation, "PDF Sheets")

    If ans = vbYes Then
        Sheets("FrontSheet").Visible = True
        Sheets("Launcher").Visible = False
        Team = Sheets("FrontSheet").Range("E21").Value
        fPath = CreateObject("WScript.Shell").specialfolders("Desktop")
        Call SelectAllSheets
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fPath & "/" & Format(Now(), "yyyymmdd") & Team & " VM", _
        openafterpublish:=True, ignoreprintareas:=False
        Sheets("Launcher").Visible = True
        Sheets("FrontSheet").Visible = False
    Else
        Exit Sub
    End If
End Sub

示例场景: -Sheet 1 有 1 页,没有页脚 -Sheet 2 有 5 个寻呼机,页脚为 Page &[Page] of &[Pages] - 然后 PDF 将在工作表 2 的底部输出 2 of 6

这是遵守 PDF 的规则,而不是工作表中的页码。有什么想法可以将其输出1 of 5(如工作簿所示)?

任何帮助表示赞赏 印花布

【问题讨论】:

    标签: vba excel pdf spreadsheet


    【解决方案1】:

    试试这个。

    With Worksheets("Launcher").PageSetup
        .RightFooter = "&""Arial""&10 Page &P of " & .Pages.Count       
    End With
    

    另外,转到页面布局 -> 页面设置,在页面选项卡中,将首页编号设置为 1。

    【讨论】:

    • 嗨丽莎,感谢您的回复。啊,我明白了,猜猜这会在页脚中添加一个静态Page X of Page X 吗?当我回到办公室时,我会试试这个!如果它有效,我会回来标记为答案。谢谢
    • 丽莎您好,感谢您的跟进。我认为我没有很好地解释我的问题陈述。您的代码会将 Page X of Page X 添加到 Excel 工作表中。但是,当我 PDF 工作簿时,它将显示例如 3 of 44 of 4(因为它们是 PDF 的第 3 页和第 4 页;而不是1 of 22 of 2,如 excel 中所示。我会用一些图片更新 OP,希望能让事情更清楚。谢谢
    • 嗨@Calico,我已经编辑了我的答案。第一个页码应设置为 1 而不是页面设置中的自动。这应该可以解决问题。
    • 抱歉回复晚了!工作完美,非常感谢!
    猜你喜欢
    • 2013-09-01
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-20
    • 2018-01-04
    • 1970-01-01
    • 2019-07-19
    相关资源
    最近更新 更多