Private Sub CommandButton1_Click()
Dim UF As UserForm1, myUF As UserForm1, strFormName As String
strFormName = "UserForm1"
For Each UF In VBA.UserForms
If UF.Caption = strFormName Then
Set myUF = UF
Exit For
End If
Next UF
If Not myUF Is Nothing Then Unload myUF
End Sub