I am looking for a better way to disable ActiveX events from running in an Excel workbook (although this applies to all Office applications with ActiveX objects).
Hope something similar to Application.EnableEvents = false, although this does not work with ActiveX.
In the example below it is trivial to use a global boolean, but I have many event handlers for my ActiveX objects, and it would be much easier for what I could universally use to temporarily disable ActiveX events. I really don't want to add an auxiliary if / exit statement for each of these methods.
To demonstrate this problem, create an ActiveX combo box on the worksheet and add the following to this module.
Public initializingContent As Boolean
Private Sub intializeAllActiveXContent()
'this doesn't apply to activeX events :'(
Application.EnableEvents = False
'this could work but is not really elegant
'change this to false to show my problem in
'the intermediate window (called not once but twice)
initializingContent = True
ComboBoxTest.Clear
ComboBoxTest.AddItem ("item1")
ComboBoxTest.AddItem ("item2")
ComboBoxTest.AddItem ("item3")
'select the top value in the box
ComboBoxTest.value = "item1"
initializingContent = False
Application.EnableEvents = True
End Sub
Private Sub ComboBoxTest_Change()
'I really don't want to have to wrap EVERY single ActiveX method
'with something like this for a whole variety of reasons...
If initializingContent Then Exit Sub
Debug.Print "do stuff I don't want to happen when intializeAllActiveXContent() runs " & _
"but I do when user changes box"
End Sub