【问题标题】:Save Excel sheet to pdf将 Excel 工作表保存为 pdf
【发布时间】:2017-01-06 11:49:17
【问题描述】:

我有一个可以将工作表保存为 pdf 格式的宏,但它不再起作用了。

With ActiveSheet.PageSetup
    .CenterHeader = strFile2
    .Orientation = xlPortrait
    .PrintArea = "a1:q21"
    '.PrintTitleRows = ActiveSheet.Rows(5).Address
    '.Zoom = False
    .FitToPagesTall = False
    .FitToPagesWide = 1
End With    

ws.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:=strFile, _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=False, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=False

我试过了

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
    :=False, OpenAfterPublish:=OpenPDFAfterCreating

它给出了相同的

无效的过程调用或参数。

宏在我同事的电脑上运行。

【问题讨论】:

    标签: excel vba pdf


    【解决方案1】:

    您是否在粘贴的代码的 sn-p 之外声明了变量?您需要将 ws 声明为工作表,否则您将遇到问题:

    Dim ws as Worksheet
    

    您需要设置 ws = ActiveSheet 才能使用它,但我建议避免使用 ActiveSheet,因为它可能会导致问题。更好的是:

    Set ws = Workbooks("**Name of your workbook**").Worksheets("**Name of worksheet**")
    
    With ws.PageSetup
    **code**
    End With
    

    希望对您有所帮助。

    【讨论】:

    • 嗨,它是从以前的修改中评论的:D。谢谢你的回答。
    猜你喜欢
    • 2020-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多