问题
I created two forms. Pressing the button 1 opens the form number 2. By closing the form number 2, the form number 1 is displayed. But this action is only done once and it stops for the second time and almost does not work. Where does the code have a problem?
code Userform1:
Private Sub ShowUserform2_Click()
UserForm1.Hide
Unload UserForm1
UserForm2.Show
End Sub
Code userform2:
Private Sub UserForm_Terminate()
UserForm2.Hide
Unload UserForm2
UserForm1.Show
End Sub
回答1:
Skip the formName.Hide
lines. They are unnecessary.
After the Unload formName
statements add:
Set formName = Nothing
Also, make the otherForm.Show
line precede the above two lines.
回答2:
Try this code:
code Userform1:
Private Sub ShowUserform2_Click()
UserForm1.Hide
UserForm2.Show
End Sub
Code userform2:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
UserForm1.Show
End Sub
来源:https://stackoverflow.com/questions/52743825/stop-in-close-and-open-userforms-vba