Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

https://stackoverflow.com/a/55926975/5079799

https://stackoverflow.com/questions/55926451/how-to-have-vba-code-wait-until-vbmodeless-userform-is-closed

https://codereview.stackexchange.com/questions/212389/user-confirmation-using-a-userform-modeless-and-doevents

Module Name doesn't Matter

UserForm Name = "UserForm1"

Class Name = "Class1"

Module Code:

Private UserFormNameStr As Class1
Public Sub DoStuff()
    Set UserFormNameStr = New Class1
    UserFormNameStr.ClassSubNameStrSubName
End Sub
Public Sub CallMeWhenUserFormClosed()
 Debug.Print "Module Code Run"
End Sub

Class Code:

Private WithEvents UserFormNameStr As UserForm1
Private Sub Class_Initialize()
    Set UserFormNameStr = New UserForm1
End Sub
Public Sub ClassSubNameStrSubName()
    UserFormNameStr.Show vbModeless
End Sub
Private Sub UserFormNameStr_Closed()
    '_Closed is required syntax
    Debug.Print "Closed Event"
    Call CallMeWhenUserFormClosed
End Sub

UserForm Code:

Public Event Closed()
Private Sub UserForm_Initialize()
    '
End Sub
Sub OkButton_Click()
 Debug.Print "Raising Events from OK Button!"
 RaiseEvent Closed
 Unload Me
End Sub
Private Sub CancelButton_Click()
 Unload Me
 End
End Sub

EventDrivenModelessUserForm.xlsm

  • No labels