运行时错误“28”:Excel VBA中的堆栈空间不足
我尝试为我的要求创build一个工作簿。 第一个工作表包含一个types为“文本”的单元格,用于DATE值。
我添加Workbook_Open方法设置今天的date时打开工作簿如下所示。
Private Sub Workbook_Open() Sheet1.Range("F6") = Date End Sub
而且我还为该单元格添加了Worksheet_Change方法。 这是validation检查如下。
Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$F$6" Then 'Getting insertion date. insertionDate = Sheet1.Range("F6") 'If date field is not empty If insertionDate <> "" Then Call MsgBox("Insertion Date must be inserted.") End If End If End Sub
之后,我testing了我的代码。 打开工作簿时,出现以下错误。
Run-time error '28': Out of stack space
当点击“Debug”button时,光标显示在Worksheet_Change方法的第一行。
我已经尝试了我所想的一切。 但是什么都没有发生。 帮我。 谢谢。
我用这个代码得到它。 我不满意,但我的问题解决了。
Private Sub Worksheet_Change(ByVal Target As Range) Application.EnableEvents = False If Target.Address = "$F$6" Then 'Getting insertion date. insertionDate = Sheet1.Range("F6") 'If date field is not empty If insertionDate <> "" Then Call MsgBox("Insertion Date must be inserted.") End If End If Application.EnableEvents = True End Sub
Msgbox
不需要Call
语句。 尝试删除Call
并再次testing。 我从https://support.microsoft.com/en-us/kb/126090?wa=wsignin1.0获得一些参考。 它可能是解释你的错误。
代码中标记的错误的可能来源
Option Explicit ' Candidate Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$F$6" Then 'Getting insertion date. Dim insertionDate as String ' Candidate insertionDate = Sheet1.Range("F6").Text ' Candidate 'If date field is not empty If insertionDate <> "" Then MsgBox("Insertion Date must be inserted.") ' Candidate End If End If End Sub
确保您将Worksheet_Change
放置在Worksheet_Change
表模块中。