一遍又一遍地从用户表单打开用户表单 - 导致对象问题
我目前在 Excel 2003 中构建了一个工具,它显示一系列数据输入表单。客户要求表单上有“上一个表单”和“下一个表单”按钮。
用于在表单之间移动的代码如下
Sub NextForm(strFormName As String)
Dim intCurPos As Integer
Dim strNewForm As String
'Find out which form we are currently on from a list in a range
intCurPos = WorksheetFunction.Match(strFormName, Range("SYS.formlist"), 0)
If intCurPos = WorksheetFunction.CountA(Range("SYS.formlist")) Then
'We want to use the first one
intCurPos = 0
End If
'Get the name of the form to open
strNewForm = WorksheetFunction.Index(Range("SYS.formlist"), intCurPos + 1)
'Load the form into the Userforms Collection
Set newForm = VBA.UserForms.Add(strNewForm)
'Show the form
newForm.Show
End Sub
我遇到的问题是,在执行此操作 25 次(是的,我知道)后,系统崩溃。我意识到这是因为每次到达上面的 newForm.Show 行时,代码都无法完成,因此位于内存中。
无模式表单可以阻止此问题,但用户可以加载其他表单并执行其他可能导致重大问题的操作。
有人有任何建议可以帮助解决这个问题吗?以某种方式强制执行代码但不停止表单的模式功能?
可能性不大,但感谢任何帮助。
I currently have built a tool in Excel 2003 which displays a series of data entry forms. The client has requested that there be "Previous Form" and "Next Form" buttons on the forms.
The code used to move between the forms is as follows
Sub NextForm(strFormName As String)
Dim intCurPos As Integer
Dim strNewForm As String
'Find out which form we are currently on from a list in a range
intCurPos = WorksheetFunction.Match(strFormName, Range("SYS.formlist"), 0)
If intCurPos = WorksheetFunction.CountA(Range("SYS.formlist")) Then
'We want to use the first one
intCurPos = 0
End If
'Get the name of the form to open
strNewForm = WorksheetFunction.Index(Range("SYS.formlist"), intCurPos + 1)
'Load the form into the Userforms Collection
Set newForm = VBA.UserForms.Add(strNewForm)
'Show the form
newForm.Show
End Sub
The issue I have is that after you do this 25 times (yeah I know) the system crashes. I realise that this is because everytime you get to the newForm.Show line above the code doesn't get to complete and so sits in memory.
Modeless forms would stop this issue but then the user could load other forms and do other things which would cause major issues.
Does anyone have any suggestions to help with this? Somehow to force code execution but not stop the modal ability of the form?
Long shot but appreciate any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许你应该改变你的方法。
我建议如下:
在主模块中使用循环来循环打开表单,并在用户每次按下“下一个表单”按钮时循环。
在每个表单中,声明:
在每个“下一个表单”按钮中,输入类似以下内容:
将您的子程序修改为提供下一个表单名称的函数
您还需要修改您的 OK 以隐藏表单,而不是卸载它并设置CloseStatus 为 true。
这个想法是在一个过程中控制所有表单从外部加载/卸载。
希望它足够清楚。
Maybe you should change your approach.
I would suggest the following:
In the main module use a loop to cycle open the form and loop every time the user press the "Next Form" button.
In every form, declare:
In every "Next Form" button, put something like:
Modify your sub to be a function that delievers the next Form Name
You will also need to modify your O.K. to just hide the form instead of unloading it and setting the CloseStatus to true.
The idea is to control all your forms loading/unloading from outside the from in a single procedure.
Hope it is clear enough.