Macro problem with protecting worksheet...........
Looks like the line that sets wks got left behind. this worked for me:
Private Sub Workbook_BeforeSave( _
ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim wks As Worksheet
Set wks = Me.Worksheets("Result")
Me.Unprotect Password:="mypassword"
With wks
.Unprotect Password:="mypassword"
.Range("K4") = Now
.Range("B4:B9,J2:M2,A26:L33,A14:L22,A39:L45," & _
"A55:L60,K4:K9").Locked = True
.Protect Password:="mypassword"
End With
Me.Protect Password:="mypassword"
End Sub
--
Regards,
Tom Ogilvy
"PKyle" wrote in message
...
Thanks, I gave both answers a shot- I'm not sure what I am missing- I
get errors with this code now.
Error runtime 91: obj variable or with block not set......
I have 5 worksheets in this workbook.
"Request"
"instructions"
"Analyses"
"Data"
"Summary"
are the 5 workbook names
I only need to lock the field ranges stated for the worksheet called
"Request", since the others are already protected.
My earlier macro works if I am in the worksheet called "request". How can
I
jump to this worksheet and display it in the before save event- so the
code
that I have that works is executed ??
ie. the before save event switches view to the "request" worksheet
as
the active sheet and then performs the working code??
Thanks
Paul
"Tom Ogilvy" wrote in message
...
Private Sub Workbook_BeforeSave( _
ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim wks as Worksheet
Me.Unprotect password:="mypassword"
With wks
.Unprotect password:="mypassword"
.Range("K4") = Now
.Range("B4:B9,J2:M2,A26:L33,A14:L22,A39:L45," & _
"A55:L60,K4:K9").Locked = True
.Protect password:="mypassword"
End With
Me.Protect password:="mypassword"
End Sub
--
Regards,
Tom Ogilvy
"PKyle" wrote in message
...
I have a workbook with 5 active worksheets. The firt worksheet is
named
"request".
If "request" is the active worksheet, it locks the fields below.... if
I
am
on another worksheet, it does not lock the fields in "request" as
noted
below.
What did I miss?
Thanks
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Sheets("Request").Range("K4") = Now
Set wks = Me.Worksheets("request")
ActiveWorkbook.Unprotect password:="mypassword"
ActiveSheet.Unprotect password:="mypassword"
Range("B4:B9").Select
Selection.Locked = True
Range("J2:M2").Select
Selection.Locked = True
Range("A26:L33").Select
Selection.Locked = True
Range("A14:L22").Select
Selection.Locked = True
Range("A39:L54").Select
Selection.Locked = True
Range("A55:L60").Select
Selection.Locked = True
Range("K4:K9").Select
Selection.Locked = True
ActiveSheet.Protect password:="mypassword"
ActiveWorkbook.Protect password:="mypassword"
End Sub
|