【问题标题】:Save as PDF hidden and protected by password EXCEL sheet另存为 PDF 隐藏并受密码保护 EXCEL 表
【发布时间】:2018-04-30 04:05:37
【问题描述】:

我使用此代码将隐藏的工作表另存为 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。我尝试使用命令“取消保护密码”,但也没有用,它一直说“.Visible = xlSheetVisible”行有问题。有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: vba excel pdf


    【解决方案1】:

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

    编辑:

       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
    

    【讨论】:

    • 非常感谢,我只是在错误的地方使用了“unprotect”!你很有帮助:)
    猜你喜欢
    • 1970-01-01
    • 2011-12-23
    • 2012-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-06
    • 2010-09-27
    相关资源
    最近更新 更多