How can I call
UserForm_Initialize() in a
Module instead of the UserForm code object?
From a module:
Just make sure that in your userform, you update the sub like so:
Public Sub UserForm_Initialize() so it can be called from outside the form.
Alternately, if the Userform hasn’t been loaded:
UserFormName.Show will end up calling
UserForm_Initialize because it loads the form.
IMHO the method UserForm_Initialize should remain private bacause it is event handler for Initialize event of the UserForm.
This event handler is called when new instance of the UserForm is created. In this even handler u can initialize the private members of UserForm1 class.
Standard module code:
Option Explicit Public Sub Main() Dim myUserForm As UserForm1 Set myUserForm = New UserForm1 myUserForm.Show End Sub
User form code:
Option Explicit Private m_initializationDate As Date Private Sub UserForm_Initialize() m_initializationDate = VBA.DateTime.Date MsgBox "Hi from UserForm_Initialize event handler.", vbInformation End Sub
After all this time, I managed to resolve the problem.
This method works best to dynamically init the current UserForm