Search code examples
excelvbacomboboxuserform

Refresh Combobox in user userform1 with close userform2 - VBA


I want to refresh userform1 combobox values by closing the userform2 window. (Without putting the commandbutton and only with the window closing)


Solution

  • Create 2 UserForms.

    On UserForm1 put this code:

    Dim WithEvents frm2 As UserForm2
    
    Private Sub frm2_Closed()     
       MsgBox "Closed!"
    End Sub
    
    
    Private Sub UserForm_Initialize()  
        Set frm2 = New UserForm2
        frm2.Show
    End Sub
    

    On Userform2 put the code:

    Public Event Closed()
    
    Private Sub UserForm_Terminate()
    RaiseEvent Closed
    End Sub
    

    You can change the code to do what you want.

    When the UserForm2 is closed, an event is raised and UserForm1 handle it.