Excel – 错误28堆栈空间

我正在处理一些包含Excel 2010中的276个表单的项目。应用程序的目的是什么:form1出现,用户input内容,然后按next,我validation用户input,所以我知道用户需要什么样的下一个表单填。 等等,但在整个过程中的某个地方,我得到了错误28:堆栈空间不足。

我已经search了互联网,但没有find任何解决方法,所以用户不会在应用程序中间中断。

基本上,我想要的是清除堆栈,如果可能的话。

编辑:

Private Sub btnNext_Click() 'Getting the column where I need to insert the value from the form Dim coll As Integer coll = findColumn("WP10200") 'Getting the row where I need to insert the value from the form Dim row As Integer row = ActiveCell.row 'Getting the user value from the textbox Dim val As String val = txtValue.Text If val >= 1 And val <= 4 Then Cells(row, coll).Value = val If val = 1 Then Unload Me WP10215.Show Else Unload Me WP10202.Show End If Else MsgBox "Not valid input" End If End Sub Function findColumn(CellVal As String) As Integer Dim rng As Range Dim cell As Range Dim coll As Integer Set rng = Range("A1:JC1") For Each cell In rng.Cells Dim tmp As String tmp = cell.Value If tmp = CellVal Then coll = cell.Column Exit For End If Next cell findColumn = coll End Function Private Sub UserForm_Initialize() Me.txtValue.SetFocus End Sub 

这个代码在所有的forms上几乎是一样的(有一些例外,即不同的input,显示一些其他的forms等等)

WP10200 – 是用户需要input内容的问题的标识。 WP10215和WP10202也是如此,它们就是这样一个具有一定逻辑的forms。

一些额外的信息 ,所有这些forms都在用户可以启动的一个macros中,并且比它填充表单时显示的更多。

当您不closures程序时会发生这种情况。 即你有Macro 1 ,调用Macro 2调用Macro 3 ,并没有closures任何closures。

您可以通过执行以下操作来检查哪些过程正在运行:

在步进模式下运行代码时,转到View > Call Stack (或按Ctrl + l )。

要解决这个问题,你需要划分各种程序。

如果您发布了一些代码,我可能会给出更好的答案。

–Update–

你的代码每个表单都很好。 我怀疑,这个问题在于你的一个macros,用户可以启动 ,而不是根据需要closures子目录。

正如我之前提到的,运行你的代码,然后当你得到错误,检查调用堆栈,看看哪些程序没有被正确closures。 然后,您需要更改程序工作stream程(谢谢@Tim Williams)来解决问题。

考虑到问题的大小(276个表格),这不太可能在这里很容易解决。