保存为PDF隐藏并受密码EXCEL表保护

时间:2017-11-16 14:52:25

标签: excel vba excel-vba pdf

我使用此代码将PDF保存为隐藏的工作表,并且它运行良好:

Sub Cite()

Dim wb As Excel.Workbook
Dim Proposalname As String
Dim iVis As XlSheetVisibility
Dim xlName As Excel.Name
Dim FolderPath As String

Set wb = ActiveWorkbook
FolderPath = ActiveWorkbook.Path & "\"

Proposalname = "Cite for " & CStr(Range("B2").Value)

'Proposal
 Application.ScreenUpdating = False
 With Worksheets(2)
 iVis = .Visible
.Visible = xlSheetVisible
.ExportAsFixedFormat Type:=xlTypePDF, _
                     Filename:=ActiveWorkbook.Path & "\" & Proposalname & ".pdf", _
                     Quality:=xlQualityStandard, _
                     IncludeDocProperties:=True, _
                     IgnorePrintAreas:=True, _
                     OpenAfterPublish:=True


 .Visible = iVis

 Worksheets(2).Activate


 End With
 Application.ScreenUpdating = True
 End Sub

但是,现在我用密码保护这个隐藏的表格,这样人们就无法取消隐藏。执行此操作后,我无法像以前那样生成PDF。我试图使用命令" Unprotect password"并且也没有奏效,它一直说这条线出了问题" .Visible = xlSheetVisible"。有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

您必须取消对工作簿和工作表的保护才能更改工作表的可见属性

编辑:

   wb.unprotect "Your password here"
   With Worksheets(2)
         iVis = .Visible
         .Visible = xlSheetVisible
more code here
End With
 wb.protect "Your password here"
Application.ScreenUpdating = True