[英]Autolock sheets when closing
我正在嘗試制作一個工作簿,其中所有工作表在關閉工作簿時自動使用密碼鎖定,但允許過濾和搜索工作簿中的表格。 我已經設法將以下命令收集在一起,這些命令除了設置密碼之外還可以工作。 任何人都可以幫忙嗎?
Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Update by Extendoffice 2018/1/24
Dim xSheet As Worksheet
Dim xPsw As String
xPsw = "***"
For Each xSheet In Worksheets
xSheet.Protect xPsw
Next
If ActiveSheet.Protection.AllowFiltering = False Then
ActiveSheet.Protect AllowFiltering:=True
End If
End Sub
*** = 密碼 目前上述自動鎖定工作表並允許根據需要進行過濾,但不設置密碼。
Excel 適用於office 365,win10企業版。
干杯!
我認為它有問題,因為您使用了兩次保護方法。 試試下面的代碼
Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Update by Extendoffice 2018/1/24
Dim wb As Workbook: Set wb = ThisWorkbook
Dim xSheet As Worksheet
Dim xPsw As String
xPsw = "testpw"
For Each xSheet In wb.Worksheets
xSheet.Protect xPsw, AllowFiltering:=True
Next
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.