Truques VBA Raramente Usados - Protect Workbook
Em muitas ocasiões desejaremos manter nossas planilhas protegidas após inserções, atualizações ou mesmo troca de versão. O que segue abaixo é o modo de mantê-las protegidas entre estes momentos.
Sub PWorkbook()Dim pwd1 As String, ShtName As String
pwd1 = InputBox("Please Enter the password")
If pwd1 = "" Then Exit Sub
ShtName = "Workbook as a whole"
ActiveWorkbook.Protect Structure:=True, Windows:=False, Password:=pwd1
MsgBox "The workbook's structure has been protected."
Exit Sub
ErrorOccured:
MsgBox "Workbook could not be Protected"
Exit Sub
End Sub
On Error GoTo ErrorOccured
Sub UnPWorkbook()On Error GoTo ErrorOccuredEnd Sub
Dim pwd1 As String, ShtName As String
pwd1 = InputBox("Please Enter the password")
If pwd1 = "" Then Exit Sub
ShtName = "Workbook as a whole"
ActiveWorkbook.Unprotect Password:=pwd1
MsgBox "The workbook's structure has been Unprotected."
Exit Sub
ErrorOccured:
MsgBox "Workbook could not be UnProtected - Password Incorrect"
Exit Sub