Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
MP MP is offline
external usenet poster
 
Posts: 39
Default Macro won't execute when Worksheet is Protected

I have a worksheet with the following macro

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrHandler
If Not Intersect(Target, Me.Range("B8")) Is Nothing Then
Target.Offset(3, 0).ClearContents
Target.Offset(4, 0).ClearContents
Target.Offset(5, 0).ClearContents
Target.Offset(6, 0).ClearContents
Target.Offset(12, 0).ClearContents
Target.Offset(16, 0).ClearContents
ErrHandler:
Application.EnableEvents = True
End If
End Sub

It works fine until I protect the worksheet, then it stops working? I tried
putting a digital signature on the macro and then accepted the digital
signature when starting the worksheet and that still does not work. Is there
something else I need to do when I protect? The cells that I am clearing are
not locked.

Thanks in advance
MP
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Macro won't execute when Worksheet is Protected

Probably need to use the Worksheets(#).Unprotect.Password("Password") at the
beginning of the macro and then reset Protect at the end of the macro.

"MP" wrote:

I have a worksheet with the following macro

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrHandler
If Not Intersect(Target, Me.Range("B8")) Is Nothing Then
Target.Offset(3, 0).ClearContents
Target.Offset(4, 0).ClearContents
Target.Offset(5, 0).ClearContents
Target.Offset(6, 0).ClearContents
Target.Offset(12, 0).ClearContents
Target.Offset(16, 0).ClearContents
ErrHandler:
Application.EnableEvents = True
End If
End Sub

It works fine until I protect the worksheet, then it stops working? I tried
putting a digital signature on the macro and then accepted the digital
signature when starting the worksheet and that still does not work. Is there
something else I need to do when I protect? The cells that I am clearing are
not locked.

Thanks in advance
MP

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,365
Default Macro won't execute when Worksheet is Protected

It works for me under the setup you describe in Excel 2003. However, I
notice that you never diabled event handling, which is going to cause the
routine to be called repeatedly for each .ClearContents. To reduce that
overhead, I rewrote it like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range("B8")) Is Nothing Then
On Error GoTo ErrHandler
Application.EnableEvents = False
Target.Offset(3, 0).ClearContents
Target.Offset(4, 0).ClearContents
Target.Offset(5, 0).ClearContents
Target.Offset(6, 0).ClearContents
Target.Offset(12, 0).ClearContents
Target.Offset(16, 0).ClearContents
ErrHandler:
Application.EnableEvents = True
On Error GoTo 0 ' reset trap
End If
End Sub


"MP" wrote:

I have a worksheet with the following macro

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrHandler
If Not Intersect(Target, Me.Range("B8")) Is Nothing Then
Target.Offset(3, 0).ClearContents
Target.Offset(4, 0).ClearContents
Target.Offset(5, 0).ClearContents
Target.Offset(6, 0).ClearContents
Target.Offset(12, 0).ClearContents
Target.Offset(16, 0).ClearContents
ErrHandler:
Application.EnableEvents = True
End If
End Sub

It works fine until I protect the worksheet, then it stops working? I tried
putting a digital signature on the macro and then accepted the digital
signature when starting the worksheet and that still does not work. Is there
something else I need to do when I protect? The cells that I am clearing are
not locked.

Thanks in advance
MP

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
execute macro on Worksheet selection Trebor Retrac Excel Programming 2 June 4th 07 01:17 AM
How to execute a macro in a protected worksheet? Ha Noi Excel Programming 2 April 4th 07 01:38 AM
Macro in a protected worksheet PA Excel Programming 4 April 25th 06 04:19 AM
How can I make macros execute on a protected sheet? J Scott Excel Programming 2 July 26th 05 04:02 PM
Record Worksheet Content as Macro and Execute from another Worksheet David McRitchie[_2_] Excel Programming 2 July 23rd 03 09:43 AM


All times are GMT +1. The time now is 06:53 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"