#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default events

I am trying to write a code in a change event in a worksheet. In the code I
need to unprotect the sheet and then protect the sheet when it is done. I
called a procedure in a module.

Sub protectsheet()
ActiveSheet.Protect
End Sub
Sub unprotectsheet()
ActiveSheet.Unprotect
End Sub

When the change event procedure ran it stopped working. I tried removing
all the code and did a simple msgbox("") and that didn't work either. What
do I need to do to unprotect and protect the sheet to run the procedure?

Also, how do I get the change event to execute again?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default events

I'm not sure that I would run the protect and unprotect from a worksheet
module using the change event. It seems to work better from the VBA module.
If the Unprotect code is triggered by the change event and you have protected
the sheet, the code cannot run because the change will not occur.

"ranswert" wrote:

I am trying to write a code in a change event in a worksheet. In the code I
need to unprotect the sheet and then protect the sheet when it is done. I
called a procedure in a module.

Sub protectsheet()
ActiveSheet.Protect
End Sub
Sub unprotectsheet()
ActiveSheet.Unprotect
End Sub

When the change event procedure ran it stopped working. I tried removing
all the code and did a simple msgbox("") and that didn't work either. What
do I need to do to unprotect and protect the sheet to run the procedure?

Also, how do I get the change event to execute again?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default events

Why not invoke unprotect and protect within the event code and dump the two
subs?

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error GoTo enditall
Application.EnableEvents = False
If Target.Cells.Column = 2 Then
ActiveSheet.Unprotect Password:="justme"
n = Target.Row
If Target.Value < "" _
And Target.Offset(0, 1).Value = "" Then
With Target.Offset(0, 1)
.Value = Now
.Locked = True
End With
End If
End If
enditall:
Application.EnableEvents = True
ActiveSheet.Protect Password:="justme", DrawingObjects:=True, _
Contents:=True, Scenarios:=True
End Sub


Gord Dibben MS Excel MVP

On Thu, 17 Jan 2008 08:10:01 -0800, ranswert
wrote:

I am trying to write a code in a change event in a worksheet. In the code I
need to unprotect the sheet and then protect the sheet when it is done. I
called a procedure in a module.

Sub protectsheet()
ActiveSheet.Protect
End Sub
Sub unprotectsheet()
ActiveSheet.Unprotect
End Sub

When the change event procedure ran it stopped working. I tried removing
all the code and did a simple msgbox("") and that didn't work either. What
do I need to do to unprotect and protect the sheet to run the procedure?

Also, how do I get the change event to execute again?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default events

I will give that a try.
Thanks

"Gord Dibben" wrote:

Why not invoke unprotect and protect within the event code and dump the two
subs?

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error GoTo enditall
Application.EnableEvents = False
If Target.Cells.Column = 2 Then
ActiveSheet.Unprotect Password:="justme"
n = Target.Row
If Target.Value < "" _
And Target.Offset(0, 1).Value = "" Then
With Target.Offset(0, 1)
.Value = Now
.Locked = True
End With
End If
End If
enditall:
Application.EnableEvents = True
ActiveSheet.Protect Password:="justme", DrawingObjects:=True, _
Contents:=True, Scenarios:=True
End Sub


Gord Dibben MS Excel MVP

On Thu, 17 Jan 2008 08:10:01 -0800, ranswert
wrote:

I am trying to write a code in a change event in a worksheet. In the code I
need to unprotect the sheet and then protect the sheet when it is done. I
called a procedure in a module.

Sub protectsheet()
ActiveSheet.Protect
End Sub
Sub unprotectsheet()
ActiveSheet.Unprotect
End Sub

When the change event procedure ran it stopped working. I tried removing
all the code and did a simple msgbox("") and that didn't work either. What
do I need to do to unprotect and protect the sheet to run the procedure?

Also, how do I get the change event to execute again?



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
do events? background events cereldine[_15_] Excel Programming 1 April 12th 06 01:06 PM
New to Events Jim May Excel Programming 2 April 10th 06 05:44 AM
events? [email protected] Excel Discussion (Misc queries) 1 September 14th 05 03:26 PM
how do I log events bmarks Excel Programming 0 December 13th 04 07:33 PM
events jacob Excel Programming 2 September 7th 04 02:15 PM


All times are GMT +1. The time now is 05:32 AM.

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"