Stop in Close and Open userforms _VBA

纵饮孤独 提交于 2021-02-10 16:48:52

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!