當代碼運行時,出現「堆棧空間不足」錯誤(28)。通常它會完全崩潰Excel,但有時我可以在打開工作表時立即「調試」。當爲循環指定命名範圍時Excel VBA'堆棧空間不足'
當它這樣做時,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不是罪魁禍首嗎?你的問題是不可複製的,因此其他人很難做出更多猜測。請參閱http://stackoverflow.com/help/mcve –
您可以嘗試'Application.EnableEvents = False'作爲事件處理程序的第一行。這將阻止事件處理程序調用的級聯,這可能是問題所在。 –