Hi all,
Mình sưu tầm được code này để khóa và mở khóa, tuy nhiên ở đây duyệt toàn bộ workbook. Mình muốn làm trên từng sheet 1 thì phải sửa như thế nào?
và
thanks!
Mình sưu tầm được code này để khóa và mở khóa, tuy nhiên ở đây duyệt toàn bộ workbook. Mình muốn làm trên từng sheet 1 thì phải sửa như thế nào?
Mã:
Sub sbProtectAllSheets()Dim pwd1 As String, pwd2 As String
pwd1 = "vtth@123"
If pwd1 = "" Then Exit Sub
pwd2 = "vtth@123"
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."
Exit Sub
End Sub
Mã:
Sub sbUnProtectAll()On Error GoTo ErrorOccured
Dim pwd1 As String
pwd1 = InputBox("Please Enter the password")
If pwd1 = "" Then Exit Sub
For Each ws In Worksheets
ws.Unprotect Password:=pwd1
Next
MsgBox "All sheets UnProtected."
Exit Sub
ErrorOccured:
MsgBox "Sheets could not be UnProtected - Password Incorrect"
Exit Sub
End Sub
thanks!