Problems protecting Worksheet with VB

Bowdlerb

New Member
Joined
Mar 6, 2002
Messages
11
I have the following code in "This Workbook" which works fine up to the point that it does not re-protect the active sheet. Any ideas why not:

Private Sub Workbook_Open()
ActiveSheet.Unprotect
If [T160].Value <> "" Then Exit Sub
[T160].Value = Format(Now, "dd/mm/yy ")
ActiveSheet.Protect
End Sub

Has me frustrated for the past hour or so!

Thanks,

Barrie Bowdler :oops:
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Probably because you exit the sub before you reprotect

Code:
Private Sub Workbook_Open() 

    ActiveSheet.Unprotect 
    If [T160].Value <> "" Then
        Else
        [T160].Value = Format(Now, "dd/mm/yy ") 
    End If
    ActiveSheet.Protect 

End Sub
 
Upvote 0
Thankyou so much for your assistance, the code works perfectly, a job very well done.

Barrie Bowdler
 
Upvote 0

Forum statistics

Threads
1,214,587
Messages
6,120,406
Members
448,958
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top