Hi all,
I'm writing a macro that among other things has to unprotect all worksheets.
Thing is I want it to work on two versions of files. each one has other password used for unprotecting.
So far I came up with this:
Private Sub Unprotect()
Application.ScreenUpdating = False
On Error Resume Next
For Each ws In ActiveWorkbook.Worksheets
If ws.ProtectContents = True And ws.Visible = xlSheetVisible Then
ws.Unprotect ("2010pass")
ws.Unprotect ("2011pass")
End If
Next ws
Application.ScreenUpdating = True
End Sub
It works, but I get the feeling it is not the best way to do this.
Does this code make macro slower if workbook has a lot of worksheets. Is there a better way to do this?
Any advice would be appreciated!
I'm writing a macro that among other things has to unprotect all worksheets.
Thing is I want it to work on two versions of files. each one has other password used for unprotecting.
So far I came up with this:
Private Sub Unprotect()
Application.ScreenUpdating = False
On Error Resume Next
For Each ws In ActiveWorkbook.Worksheets
If ws.ProtectContents = True And ws.Visible = xlSheetVisible Then
ws.Unprotect ("2010pass")
ws.Unprotect ("2011pass")
End If
Next ws
Application.ScreenUpdating = True
End Sub
It works, but I get the feeling it is not the best way to do this.
Does this code make macro slower if workbook has a lot of worksheets. Is there a better way to do this?
Any advice would be appreciated!