首页 > 解决方案 > 我无法追踪崩溃问题,因为 VBA 一直给我一个“无法进入中断模式”错误

问题描述

我有一个包含 10,000 个行文件的长宏。最后我尝试 fileSaveName。如果我只运行宏,它会一直崩溃。我无法追踪出了什么问题,因为如果我单步执行,我会在保存代码附近的任何地方看到“无法进入中断模式”。如果我“跑到光标”,也会发生同样的事情。然后当我点击“继续”时,宏运行到最后就好了。

当我放入“Debug.Assert”中断时,单击“继续”后宏运行良好。

'获取活动工作簿文件夹,如果保存

strPath = wbA.Path
If strPath = "" Then
  strPath = Application.DefaultFilePath
End If
strPath = strPath & "\"

'为保存文件创建默认名称

strFile = QuoteNo & " - OEM List"
strPathFile = strPath & strFile

'现在用消息框保存

fileSaveName = Application.GetSaveAsFilename(InitialFileName:=strFile, FileFilter:="Excel workbook (*.xlsx), *.xlsx", Title:="Save with this file name or Create a new name")

If fileSaveName <> False Then
  ActiveWorkbook.SaveAs Filename:=fileSaveName
End If

只需逐步完成文件重新格式化和过滤并保存文件而不会破坏。

标签: excelvbacrashbreakpoints

解决方案


推荐阅读