Excel - 错误28堆栈空间

时间:2014-07-28 16:49:47

标签: excel excel-vba vba

我正在开发一个包含Excel 2010中276个表单的项目。应用程序的目的是什么:form1出现,用户输入内容,按next并验证用户输入,所以我知道下一个表单是什么用户需要填写。所以继续,但在整个过程的中间某处我得到错误28:堆栈空间不足。

我搜索了互联网,但没有找到解决方法,因此用户不会在应用程序中途被打断。

基本上,我想要的是以某种方式清除堆栈,如果可能的话。

修改

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

此代码在所有形式中几乎相同(有一些例外,即不同的输入,显示其他形式等等)

WP10200 - 是用户输入内容所需问题的ID。 WP10215和WP10202也是这样的形式,里面有一些逻辑。

其他一些信息,所有这些表单都在用户可以启动的一个宏中,而不是在它们显示时填充表单。

1 个答案:

答案 0 :(得分:0)

当您不关闭程序时会发生这种情况。即您Macro 1拨打Macro 2来拨打Macro 3,然后打开和关闭,而不关闭其中任何一个。

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

在步骤模式下运行代码时,请转到View&gt; Call Stack(或者只需按Ctrl + l)。

要解决此问题,您需要划分各种程序。

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

- 更新 -

每个表单的代码都没问题。我怀疑,问题在于你的一个用户可以启动的宏,而不是根据需要关闭子。

正如我之前提到的,运行您的代码,然后当您收到错误时,检查调用堆栈以查看哪些过程未正确关闭。然后,您需要更改过程工作流程(感谢@Tim Williams)来解决问题。

考虑到问题的大小(276个表格),这可能不会在这里容易修复。