events - VBA EnableEvents fire textbox_change -


i have textbox code on change, , if press button following code

private sub commandbutton1_click()  application.enableevents = false  textbox1.text = "new text"  application.enableevents = true end sub 

but still fires on change event of textbox.

this happens because application.enableevents allows enabling/disabling events fired application (i.e. excel).

in case, parent firing textbox1 change not application rather userform. example cpearson how create own enableevents property on userform. report content of link here (to avoid "link-only answer"):

to suppress events in form, can create variable @ form's module level called "enableevents" , set false before changing property cause event raised.

public enableevents boolean private sub userform_initialize()     me.enableevents = true end sub  sub something()    me.enableevents = false    ' code cause event run    me.enableevents = true end sub  

then, of controls on form should have test if variable order of business in event code. example,

private sub listbox1_change()     if me.enableevents = false         exit sub     end if     msgbox "list box change" end sub 

you can declare enableevents private if procedures form need suppress events. however, if have forms programmatically linked together, such userform2 adding item listbox on userform1, should declare variable public , set form code following:

userform1.enableevents = false ' ' change on userform1 ' userform1.enableevents = true 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -