我目前在 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 行时,代码都没有完成,因此位于内存中。
无模式表单将停止此问题,但随后用户可以加载其他表单并执行其他会导致重大问题的事情。
有没有人有任何建议可以帮助解决这个问题?以某种方式强制执行代码但不停止表单的模态能力?
远射,但感谢任何帮助。