几天前,此宏成功保护了所有工作表,并将工作簿的副本以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,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