首页 > 解决方案 > 为什么我的 ExportAsFixedFormat 不起作用?

问题描述

几天前,此宏成功保护了所有工作表,并将工作簿的 PDF 副本保存在放置 excel 文件的同一文件夹地址中。

今天我尝试运行宏,当涉及到 PDF 步骤时,它会显示消息

运行时错误 5:无效的过程调用或参数

我该如何解决?

谢谢你们

Sub pdf()
'
' pdf Macro
'

'

     Dim pwd1 As String, pwd2 As String
    pwd1 = InputBox("Please Enter the password")
    If pwd1 = "" Then Exit Sub
    pwd2 = InputBox("Please re-enter the password")

    If pwd2 = "" Then Exit Sub

     'Check if both the passwords are identical
    If InStr(1, pwd2, pwd1, 0) = 0 Or _
    InStr(1, pwd1, pwd2, 0) = 0 Then
        MsgBox "You entered different passwords. No action taken"
        Exit Sub
    End If

    For Each ws In Worksheets
        ws.Protect Password:=pwd1
    Next

    MsgBox "All sheets Protected."
    ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    ThisWorkbook.Path & "\" & ActiveWorkbook.Name _
    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
    :=False, OpenAfterPublish:=True

End Sub

标签: excelvbapdf-generation

解决方案


推荐阅读