Password Protect Worksheet

G

Guest

I currently have a macro that locks the worksheet once it is passed a month
end date so that no more data can be entered on that worksheet
The worksheet locks fine, however the user is still able to use the
unprotect feature, despite the password been entered when I ran the macro

Private Sub Worksheet_Activate()
' LockSheet After a Specified Date

Dim CheckDate As Date
Dim CurrentDate As Date

CheckDate = Range("IU1").Value
CurrentDate = Range("IV1").Value

If CurrentDate > CheckDate Then

ActiveSheet.Protect Password:=Range("IV2")
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlNoSelection
Else

ActiveSheet.Unprotect Password:=Range("IV2")

End If

End Sub

Any advise would be appreciated
TIA
 
K

Ken Johnson

mmc308 said:
I currently have a macro that locks the worksheet once it is passed a month
end date so that no more data can be entered on that worksheet
The worksheet locks fine, however the user is still able to use the
unprotect feature, despite the password been entered when I ran the macro

Private Sub Worksheet_Activate()
' LockSheet After a Specified Date

Dim CheckDate As Date
Dim CurrentDate As Date

CheckDate = Range("IU1").Value
CurrentDate = Range("IV1").Value

If CurrentDate > CheckDate Then

ActiveSheet.Protect Password:=Range("IV2")
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlNoSelection
Else

ActiveSheet.Unprotect Password:=Range("IV2")

End If

End Sub

Any advise would be appreciated
TIA

I ran your code (xl2003) and had to supply the password I typed into
IV2 for protection to be removed so the code is fine.

Ken Johnson
 
G

Guest

This line of code protects the sheet...
ActiveSheet.Protect Password:=Range("IV2")
Since you do not specify it will use the active sheet. Do you have the
password in Cell IV2 of the active sheet? if that cell is blank then there is
no password and the spreadsheet will act as you have indicted. Either fill in
the password on the active sheet or premise Range("IV2") with the sheet the
password comes from.
 
G

Guest

Jim

Thanks for the reply

Michael

Jim Thomlinson said:
This line of code protects the sheet...
ActiveSheet.Protect Password:=Range("IV2")
Since you do not specify it will use the active sheet. Do you have the
password in Cell IV2 of the active sheet? if that cell is blank then there is
no password and the spreadsheet will act as you have indicted. Either fill in
the password on the active sheet or premise Range("IV2") with the sheet the
password comes from.
 
G

Guest

Ken
Thanks for your help your right, it does work, although for a period of
opening the workbook it would'nt, recreated this book same code all is OK
many Thanks Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top