つらつら Excel VBA

私の備忘録です。

シートの保護解除

Dim wsh As Worksheet
Set wsh = ThisWorkbook.ActiveSheet

If wsh.ProtectContents Then
    wsh.Unprotect Password:="Password"
End If

wsh.Protect Password:="Password"

Set wsh = Nothing

※シート保護されていれば保護解除し、最後にシート保護をする。意味無い