Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Macro problem with protecting worksheet...........

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro problem with protecting worksheet...........

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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Macro problem with protecting worksheet...........

If you don't tell VB which sheet to work on it uses the active sheet

Range("B4:B9").Select


doesn't name a sheet while this does:

wks.Range("B4:B9").Select

Also, don't you want to unprotect wks rather than the active sheet?:

wks.Unprotect password:="mypassword"


Btw, all you selecting/locking code can be boiled down to one line since
selecting isn't necessary:

wks.Range("B4:B9,J2:M2,A26:L33,A14:L22,A39:L54,A55 :L60,K4:K9").Locked =
True

--
Jim Rech
Excel MVP
"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
|
|


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Macro problem with protecting worksheet...........

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






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Macro problem with protecting worksheet...........

That's what I thought too- I had already tried that. The next error I get
is `1004- unable to set locked property with the range locked statement....
I'm going to split them out one by one again to see where it might be
hanging up.
??
Thanks
Paul.



"Tom Ogilvy" wrote in message
...
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










  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Macro problem with protecting worksheet...........

Its hanging with two cell ranges: B4:B9 and K4:K9 (I apostrophied
B4:B9 and then it provides an error for the last one- K4:K9)
I'm puzzled as to why it is finding errors with these cells. THey are
unprotected....

Paul

"Tom Ogilvy" wrote in message
...
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










  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro problem with protecting worksheet...........

Perhaps they make up a part of a merged cell area.

As I said, on a pristine worksheet, the code worked fine for me.

--
Regards,
Tom Ogilvy

"PKyle" wrote in message
...
Its hanging with two cell ranges: B4:B9 and K4:K9 (I apostrophied
B4:B9 and then it provides an error for the last one- K4:K9)
I'm puzzled as to why it is finding errors with these cells. THey are
unprotected....

Paul

"Tom Ogilvy" wrote in message
...
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












  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Macro problem with protecting worksheet...........

one group is a merged cell group, the other? I'll have to check... will
try when I get home this evening
Didnt' think that could be it, and almost put those words in the text- one
was a merged group of cells!

Thanks!

Paul

"Tom Ogilvy" wrote in message
...
Perhaps they make up a part of a merged cell area.

As I said, on a pristine worksheet, the code worked fine for me.

--
Regards,
Tom Ogilvy

"PKyle" wrote in message
...
Its hanging with two cell ranges: B4:B9 and K4:K9 (I apostrophied
B4:B9 and then it provides an error for the last one- K4:K9)
I'm puzzled as to why it is finding errors with these cells. THey are
unprotected....

Paul

"Tom Ogilvy" wrote in message
...
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














  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Macro problem with protecting worksheet...........

That was it!
took a while to get to it....(sunday night) and kept forgetting that I
needed to save only while macros were disabled.

It works like a charm. Now I can implement a form that will work!

Thanks
Paul


"Tom Ogilvy" wrote in message
...
Perhaps they make up a part of a merged cell area.

As I said, on a pristine worksheet, the code worked fine for me.

--
Regards,
Tom Ogilvy

"PKyle" wrote in message
...
Its hanging with two cell ranges: B4:B9 and K4:K9 (I apostrophied
B4:B9 and then it provides an error for the last one- K4:K9)
I'm puzzled as to why it is finding errors with these cells. THey are
unprotected....

Paul

"Tom Ogilvy" wrote in message
...
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














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
Protecting worksheet Patricia Excel Discussion (Misc queries) 1 March 15th 10 02:49 PM
Protecting worksheet Kimti Excel Worksheet Functions 1 July 6th 08 01:37 AM
Password Protecting an Excel file problem Tolga Excel Discussion (Misc queries) 2 March 6th 08 02:54 PM
hiding macro codes upon protecting the worksheet eehj23 Excel Discussion (Misc queries) 1 April 28th 06 03:55 AM
Protecting worksheet Shilps Excel Programming 2 April 27th 04 01:01 PM


All times are GMT +1. The time now is 12:31 PM.

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

About Us

"It's about Microsoft Excel"