EnableEvents starting out as False on userform initialization???

birdieman

Well-known Member
Joined
Jan 13, 2016
Messages
551
I understand how EnableEvents works and I have "If EnableEvents = FALSE Then Exit" code in each BeforeUpdate event on my userform. My issue is that, for some reason, EnableEvents is starting out as FALSE when I run the userform (from the VB editor) even though I did not set it that way. My initialize event has one line (it will eventually have more), which sets a variable value, and nothing else. When I add "enableevents=True" to my one-line initialization code, all textboxes work correctly.

So my questions

1. Is EnableEvents automatically set to FALSE when the userform is run from the VB editor?

2. Any other thoughts?

thanks
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi,

The main issue I get with EnableEvents is when I disable events at the start of a macro and re-enable them at the end. Everything is OK until the code fails for some reason and the final re-enabling does not happen.

I usually write my code like this:
Code:
Sub Events()
    On Error GoTo err
    Application.EnableEvents = False
    
    ' carry out processing here
    
err:
    Application.EnableEvents = True
End Sub


Regards,
 
Upvote 0
EnableEvents is a boolean variable that you created. It initially starts with the default value, False.
You need to set it to true in the Userform's Intialize event.

(This is why I prefer a DisableEvents variable)
 
Upvote 0
thanks to both of you -- I learn something every time I come here. (I will read up on Disable Events)
 
Upvote 0
No, don't read up on Disable Events. There is nothing to read up on.

DisableEvents is a variable that I use in several projects.
Just as EnableEvents is a variable that other use in their projects.

They are different variable names for inverse approaches to manually controlling user form event code.

The EnableEvents mentioned in the OP is very different than the Application.EnableEvents that is a part of the Excel object model.
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,462
Members
449,085
Latest member
ExcelError

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top