Disable SelectionChange Event

G

Guest

I have a spreadsheet which has code behind the SelectionChange event. When I
am working on (editing) the worksheet, I want the code active. Later, when I
run a macro to do processing on the worksheet, I want this code deactivated.

Is it possible to use EnableEvents and specify a specific workbook and/or
worksheet and/or event (the SelectionChange event), or does EnableEvents
always apply to the entire application? Is there anyway to disable a
specific event, or is that ever really necessary?

Does EnableEvents affect anything other than workbook and worksheet events?
It seemed to bypass an InputBox sequence when I set it equal to false in one
test.
 
D

Dave Peterson

Application.enableevents is an application property.

You could turn it off before you do anything in your macro--it'll affect both
workbook, worksheet and application events.

If you want to be more specific, you could set up a global variable:

Public BlkMyEvents as boolean

sub testme()
blkmyevents = true
'do something that would cause a specific event to fire
'select a cell on a worksheet with a _selectionchange procedure
blkmyevents = false
end sub

Then behind that worksheet:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
if blkmyevents = true then exit sub
'normal code here.
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top