【发布时间】:2016-11-06 22:42:12
【问题描述】:
运行此代码时,我收到“堆栈空间不足”错误 (28)。通常它会使 Excel 完全崩溃,但有时我可以在打开工作表后立即“调试”。
当它出现时,VBA 编辑器会突出显示Set FormulaRange = Me.Range("M3:M61") 行。
我认为问题可能是由于 "M3:M61" 范围实际上是 Excel 表中的一个命名范围(如下一行
'Set FormulaRange = Workbooks("Advance Request & Tracking Form rebuild.xlsm").Range("tbl_interface[Liquidation in]").RefersToRange 所示,我已将其注释掉,因为我永远无法让它工作。
Option Explicit
Private Sub Worksheet_Calculate()
Dim FormulaRange As Range
Dim countdownRange As Range
Dim NotSentMsg As String
Dim MyMsg As String
Dim SentMsg As String
Dim MyLimit As Double
Dim countdownFeedbackOffset As Double
NotSentMsg = "Not Sent"
SentMsg = "Sent"
'Below the MyLimit value it will run the macro
MyLimit = 1
'Set the range with Formulas that you want to check
Set FormulaRange = Me.Range("M3:M61")
'Set FormulaRange = Workbooks("Advance Request & Tracking Form rebuild.xlsm").Range("tbl_interface[Liquidation in]").RefersToRange
'MsgBox FormulaRange
countdownFeedbackOffset = 2
On Error GoTo EndMacro:
For Each FormulaCell In FormulaRange.Cells
With FormulaCell
If IsNumeric(.Value) = False Then
.Offset(0, 3).Value = "Not numeric"
MyMsg = "Not numeric"
Else
If .Value < MyLimit Then
MyMsg = SentMsg
If .Offset(0, countdownFeedbackOffset).Value = NotSentMsg Then
Call Mail_adv_liq_reminder
'Call Mail_with_outlook1
End If
Else
MyMsg = NotSentMsg
End If
End If
Application.EnableEvents = False
.Offset(0, countdownFeedbackOffset).Value = MyMsg
Application.EnableEvents = True
End With
Next FormulaCell
ExitMacro:
Exit Sub
EndMacro:
Application.EnableEvents = True
MsgBox "Some Error occurred." _
& vbLf & Err.Number _
& vbLf & Err.Description
End Sub
这让我有点难以置信,它可能会窒息 - 该范围内实际上只有 6 个不是空白的单元格 - 但我不知道它还能是什么。
【问题讨论】:
-
你确定
Mail_adv_liq_reminder不是罪魁祸首吗?您的问题是不可重现的,因此其他人除了猜测它是什么之外很难做任何事情。见stackoverflow.com/help/mcve -
您可以尝试将
Application.EnableEvents = False作为事件处理程序的第一行。这将防止级联事件处理程序调用,这可能是问题。
标签: excel stack-overflow vba