求助大神,遇到一个多个userform嵌套之显示与关闭的问题,帮忙调试一下~~ |
想实现的效果: 运行sub,userform1显示; 点击userform1的CommandButton,则userform1隐藏,userform2显示,点击userform2的CommandButton,则userform2隐藏,userform3显示,点击userform3的CommandButton,则userform3隐藏; 在userform1中,若点击userform1的关闭按钮,则退出sub; 在userform2中,若点击userform2的关闭按钮,则返回userform1,即userform2隐藏,userform1显示; 在userform3中,若点击userform3的关闭按钮,则返回userform2,即userform3隐藏,userform3显示;
代码如下: Sub text() UserForm1.Show End Sub Sub 结束程序() End End Sub userform1
Private Sub CommandButton1_Click()
UserForm1.Hide
UserForm2.Show
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
Call 结束程序
End If
End Sub
userform2
Private Sub CommandButton1_Click()
UserForm2.Hide
UserForm3.Show
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
UserForm1.Show
UserForm2.Hide
End If
End Sub
userform3
Private Sub CommandButton1_Click()
UserForm3.Hide
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
UserForm2.Show
UserForm3.Hide
End If
End Sub
我在实际操作时发现: 在userform2中,点击userform2的关闭按钮,返回了userform1,点击userform1的CommandButton,会报错,如果加on error resume next,出现userform2显示了,但是此时userform2的关闭按钮点击无效了,不能返回ursrform1,只有CommandButton可以点; 在userform3中也是这样子,会报错,如果加on error resume next,点击userform3关闭按钮——返回userform2——确认——显示userform3,此时userform3的关闭按钮点击无效,只有CommandButton可以点。
求助大神指导一下
|