Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

Module Name doesn't Matter

UserForm Name = "UserForm1"

Class Name = "Class1"

Module Code:

Private UserFormNameStr As Class1
Public Sub DoStuff()
    Set UserFormNameStr = New Class1
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 Sub


  • No labels