Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Disabling Events

I use the following code to disable macros, but it is to indiscriminate.

Application.EnableEvents = True

Is there any way to disable only Private Sub Worksheet_SelectionChange
events and still allow other events to happen?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Disabling Events

One way:

Create a global variable (say "bSELECTIONCHANGE").

Then wrap your event macro:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If bSELECTIONCHANGE Then
'... your macro here...
End If
End Sub

Turn off the macro using

bSELECTIONCHANGE = False

and turn it back on with

bSELECTIONCHANGE = True



In article ,
"Patrick Simonds" wrote:

I use the following code to disable macros, but it is to indiscriminate.

Application.EnableEvents = True

Is there any way to disable only Private Sub Worksheet_SelectionChange
events and still allow other events to happen?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Disabling Events

I do not know how to create a global variable or where to place it when I
do.


"JE McGimpsey" wrote in message
...
One way:

Create a global variable (say "bSELECTIONCHANGE").

Then wrap your event macro:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If bSELECTIONCHANGE Then
'... your macro here...
End If
End Sub

Turn off the macro using

bSELECTIONCHANGE = False

and turn it back on with

bSELECTIONCHANGE = True



In article ,
"Patrick Simonds" wrote:

I use the following code to disable macros, but it is to indiscriminate.

Application.EnableEvents = True

Is there any way to disable only Private Sub Worksheet_SelectionChange
events and still allow other events to happen?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Disabling Events

You can put the global variable in a general module:

Option Explicit
Public bSELECTIONCHANGE As Boolean

Then for a very basic (pronounced bad) example (behind a worksheet).

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Columns(1)) Is Nothing Then Exit Sub

bSELECTIONCHANGE = True
'next line changes selection, so the _selectionchange event will fire
Me.Cells(Target.Row, "E").Select
bSELECTIONCHANGE = False

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If bSELECTIONCHANGE = True Then Exit Sub
'your regular code here
MsgBox "made it to the _selectionchange ""real"" code"
End Sub




Patrick Simonds wrote:

I do not know how to create a global variable or where to place it when I
do.

"JE McGimpsey" wrote in message
...
One way:

Create a global variable (say "bSELECTIONCHANGE").

Then wrap your event macro:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If bSELECTIONCHANGE Then
'... your macro here...
End If
End Sub

Turn off the macro using

bSELECTIONCHANGE = False

and turn it back on with

bSELECTIONCHANGE = True



In article ,
"Patrick Simonds" wrote:

I use the following code to disable macros, but it is to indiscriminate.

Application.EnableEvents = True

Is there any way to disable only Private Sub Worksheet_SelectionChange
events and still allow other events to happen?


--

Dave Peterson
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
Prevent user disabling events JP Farrow Excel Programming 1 September 29th 04 04:49 PM
Disabling/enabling events with a button created by code?? Simon Lloyd[_518_] Excel Programming 5 July 7th 04 12:09 PM
Disabling Alt+F11 richard_b2004 Excel Programming 3 May 17th 04 06:32 PM
Disabling Events MWE[_28_] Excel Programming 4 February 6th 04 05:39 AM
Auto_Open disabling Tritan Excel Programming 6 July 22nd 03 11:48 AM


All times are GMT +1. The time now is 09:43 PM.

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"