Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default prevent event procedure under condition


is it possible to stop the selection change event procedure from being
triggered from within a worksheet change event code
i.e i have an event by slection that will begin the start of event by
change but keeps looping when triggered
if the change would stop the selection code once activated it will
prevent any looping

hope this makes sense i would imagine it be something similar to
either
exit private sub worksheet_selectionchange
or
end provate sub worksheet_selectionchange
however neither of these codes work

please help me thanks


--
short_n_curly
------------------------------------------------------------------------
short_n_curly's Profile: http://www.excelforum.com/member.php...o&userid=21576
View this thread: http://www.excelforum.com/showthread...hreadid=382587

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default prevent event procedure under condition

Use Application.EnableEvents = False to stop events from firing.
Set it back to true at the appropriate place in your code.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"short_n_curly"

wrote in message
news:short_n_curly.1rau2l_1119899158.6547@excelfor um-nospam.com...

is it possible to stop the selection change event procedure
from being
triggered from within a worksheet change event code
i.e i have an event by slection that will begin the start of
event by
change but keeps looping when triggered
if the change would stop the selection code once activated it
will
prevent any looping

hope this makes sense i would imagine it be something similar
to
either
exit private sub worksheet_selectionchange
or
end provate sub worksheet_selectionchange
however neither of these codes work

please help me thanks


--
short_n_curly
------------------------------------------------------------------------
short_n_curly's Profile:
http://www.excelforum.com/member.php...o&userid=21576
View this thread:
http://www.excelforum.com/showthread...hreadid=382587



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default prevent event procedure under condition

I am assuming that your selection change event code triggers a selection
change and that is resulting in a recursive call. To fix that you can set
application.enableEvents to ignore the events something like this

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error GoTo ErrorHandler
Application.EnableEvents = False

ErrorHandler:
Application.EnableEvents = True
End Sub

As always when switching application settings it is safest to have an error
handler to reset the applicaton in case your code crashes...
--
HTH...

Jim Thomlinson


"short_n_curly" wrote:


is it possible to stop the selection change event procedure from being
triggered from within a worksheet change event code
i.e i have an event by slection that will begin the start of event by
change but keeps looping when triggered
if the change would stop the selection code once activated it will
prevent any looping

hope this makes sense i would imagine it be something similar to
either
exit private sub worksheet_selectionchange
or
end provate sub worksheet_selectionchange
however neither of these codes work

please help me thanks


--
short_n_curly
------------------------------------------------------------------------
short_n_curly's Profile: http://www.excelforum.com/member.php...o&userid=21576
View this thread: http://www.excelforum.com/showthread...hreadid=382587


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default prevent event procedure under condition

Just some added information:

Jim, either you mistyped or misread. He said the change event is causing a
selectionchange to fire.

In any event, while the solution is certainly applicable, a better all
around solution might be to avoid making a selection in the change event.
In other words, if the OP is using recorder style code like

Range("A1").Select
Selection.Value = 21
Range("B9").Select

then this should be avoided with just

range("A1").Value = 21

which doesn't trigger a selectionchange.

--
Regards,
Tom Ogilvy



"Jim Thomlinson" wrote in message
...
I am assuming that your selection change event code triggers a selection
change and that is resulting in a recursive call. To fix that you can set
application.enableEvents to ignore the events something like this

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error GoTo ErrorHandler
Application.EnableEvents = False

ErrorHandler:
Application.EnableEvents = True
End Sub

As always when switching application settings it is safest to have an

error
handler to reset the applicaton in case your code crashes...
--
HTH...

Jim Thomlinson


"short_n_curly" wrote:


is it possible to stop the selection change event procedure from being
triggered from within a worksheet change event code
i.e i have an event by slection that will begin the start of event by
change but keeps looping when triggered
if the change would stop the selection code once activated it will
prevent any looping

hope this makes sense i would imagine it be something similar to
either
exit private sub worksheet_selectionchange
or
end provate sub worksheet_selectionchange
however neither of these codes work

please help me thanks


--
short_n_curly
------------------------------------------------------------------------
short_n_curly's Profile:

http://www.excelforum.com/member.php...o&userid=21576
View this thread:

http://www.excelforum.com/showthread...hreadid=382587




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
workbook_Open event Procedure peerless Excel Discussion (Misc queries) 1 May 22nd 06 10:21 PM
workbook_Open event Procedure peerless Excel Discussion (Misc queries) 0 May 22nd 06 10:16 PM
Event Procedure Paul Johnson[_2_] Excel Programming 1 February 2nd 05 01:29 PM
Event Procedure again Paul Johnson[_2_] Excel Programming 1 February 2nd 05 01:28 PM
OnTime event not firing in Workbook_Open event procedure GingerTommy Excel Programming 0 September 24th 03 03:18 PM


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