Userform Initialize

  • Thread starter Thread starter TotallyConfused
  • Start date Start date
T

TotallyConfused

Can someone please explain "Initialize" in when working with Userforms in
Excel? How to implement in Userform? Thank you in advance for help on this.
 
The initialize event occurs when you LOAD or SHOW a user form e.g.

Load UserForm1

UserForm1.Show

You can put your own code into this event so that you can set up objects on
the UserForm (control defaults etc), other conditions or run other sub
routines that are required to run before the UserForm is loaded into memory
and or show(n) to the user. Each UserForm has its own initialize event which
is stored on the UserForm code sheet. e.g.

Private Sub UserForm_Initialize()
' put code in here to run when the UserForm is load(ed) or show(n)

End Sub

Note that the UserForm reference above is always the same regardless on the
actual UserForm name
 
This is not totally correct.

The Initialize event is triggered when the form is loaded, or if a control
on a non-loaded form is referenced.

The Activate is triggered when the form is shown.

So, for a form that is loaded and shown and then hidden and re-shown a
number of times, the Initialize event is fired once, the Activate is fired
each time. For a form that is loaded then unloaded, the re-loaded, unloaded,
etc., the Initialize event and the Activate is fired each time.

Note that if you show a form that has not yet been loaded, it will
automatically load and trigger the Initialize event as well.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Thanks for the clarity Bob, I should have remembered as I rely on it in some
of my applications! With a hide/unhide of loaded forms, if the initialize
event fired each time my form settings data would be lost!

Cheers

--

Regards,
Nigel
(e-mail address removed)
 

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

Back
Top