简体   繁体   English

Excel-错误28出栈空间

[英]Excel - error 28 out stack space

I am working on some project that contains 276 forms in Excel 2010. What is the purpose of the application: form1 appears, users input something, press next and I validate the user input so I know what is the next form that the user needs to fill. 我正在处理一个包含Excel 2010中276个表单的项目。该应用程序的目的是:出现form1,用户输入内容,按next,然后我验证用户输入,因此我知道用户需要的下一个表单是什么。填。 And so goes on, but somewhere in the middle of the whole process I get the error 28: out of stack space. 依此类推,但是在整个过程的中间,我出现了错误28:堆栈空间不足。

I have searched the internet, but didn't found any way to solve this, so the user won't be interrupted in the middle of the application. 我已经搜索了互联网,但没有找到解决此问题的任何方法,因此不会在应用程序中间中断用户。

Basically, what I want is somehow to clear the stack, if it is possible. 基本上,如果可能的话,我想要的是以某种方式清除堆栈。

EDIT: 编辑:

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

This code is almost same in all forms (with some exceptions, ie different input, displaying some other form and so on) 该代码在所有形式上几乎都是相同的(除了一些例外,即不同的输入,显示其他形式等等)。

WP10200 - is the id of the question the user needs to input something. WP10200-是用户需要输入内容的问题的ID。 WP10215 and WP10202 too, they are forms like this one with some logic inside. WP10215和WP10202也是,它们都是这种形式,内部有一些逻辑。

Some additional info , all of these forms are in one macro that the user can start, and than it fills the forms as they show up. 一些附加信息 ,所有这些表单都位于用户可以启动的一个宏中,然后它会在表单显示时填充它们。

This happens when you don't close out procedures. 当您不关闭过程时,就会发生这种情况。 Ie you have Macro 1 that calls Macro 2 which calls Macro 3 , and on and on without closing any of them down. 也就是说,您具有调用Macro 2 Macro 1Macro 2调用了Macro 3 ,然后不停地关闭它们。

You can check which procedures are running, by doing the following: 您可以通过执行以下操作检查正在运行的过程:

While running your code in step mode, go to View > Call Stack (or just press Ctrl + l ). 在步进模式下运行代码时,请转到View > Call Stack (或只需按Ctrl + l )。

To fix this, you'll need to compartmentalize the various procedures. 要解决此问题,您需要将各种过程分开。

I may be able to give a better answer if you posted some of your code. 如果您发布了一些代码,我也许可以给出更好的答案。

--Update-- --Update--

Your code per form is fine. 您的每张表格代码都可以。 The issue, I suspect, lies is your one macro that the user can start that isn't closing out subs as needed. 我怀疑,问题出在用户可以启动的一个宏,它并没有按需关闭子对象。

As I mentioned before, run your code, then when you get the error, check the call stack to see what procedures aren't being closed properly. 如前所述,运行您的代码,然后在收到错误时,检查调用堆栈以查看未正确关闭哪些过程。 You'll then need to change the procedure workflow (Thanks @Tim Williams) to fix the problem. 然后,您需要更改过程工作流程(感谢@Tim Williams)以解决问题。

Given the size of the problem (276 forms) this isn't likely going to be something that will be easily fixed here. 考虑到问题的大小(276个表格),在这里不太容易解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM