Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Password Protect Worksheet

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default Password Protect Worksheet


mmc308 wrote:
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Password Protect Worksheet

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.

--
HTH...

Jim Thomlinson


"mmc308" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Password Protect Worksheet

Jim

Thanks for the reply

Michael

"Jim Thomlinson" wrote:

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.

--
HTH...

Jim Thomlinson


"mmc308" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Password Protect Worksheet

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

"Ken Johnson" wrote:


mmc308 wrote:
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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way that I can password protect a worksheet Lin4it Excel Worksheet Functions 3 November 27th 08 03:37 PM
Password Protect a Worksheet joinme4coffee Excel Discussion (Misc queries) 8 October 28th 07 07:02 PM
Protect a worksheet with a password colettey29 Excel Worksheet Functions 2 September 26th 06 05:51 PM
Password protect a worksheet Anolan Excel Programming 1 July 20th 06 07:05 PM
Password Protect Worksheet r wilcox Excel Programming 1 July 13th 05 08:17 PM


All times are GMT +1. The time now is 12:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"