Macro- not re-password protecting

  • Thread starter Thread starter Roady
  • Start date Start date
R

Roady

Hi:

I am using a macro that involves unprotecting and protecting the sheet at
the beginning and end of the macro. I have used this same code in a different
spreadsheet's macro and it worked fine (including the allow filter part).
However, when I run it on this spreadsheet, it re-protects it at the end, but
WITHOUT the password. the code I am using is as follows:

Sub Macro1()
ActiveSheet.Unprotect Password:="Stars"

(All Macro details go here...)

ActiveSheet.Protect Password:="Stars"
ActiveSheet.Protect AllowFiltering:=True

End Sub

Do you have any idea why it protects it but without the necessary password?
thank you!
 
The second Activesheet.Protect has no password so wipes out the first
Activesheet.Protect

Use this construct

With ActiveSheet
.Protect Password:="Stars"
.EnableAutoFilter = True
End With


Gord Dibben MS Excel MVP
 
Back
Top