vba 在 Excel 中抑制保存更改对话框的两种方法不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6845457/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 13:42:28  来源:igfitidea点击:

Two methods of suppressing the save changes dialog in Excel are not working

excelexcel-vbavba

提问by James

Before setting Application.DisplayAlerts = FalseIt gets set to falseYet it still gives me the save as!

在设置 Application.DisplayAlerts = False 之前它被设置为 false然而它仍然给了我另一种选择!

For those who don't like images:

对于那些不喜欢图像的人:

  Close logFile
  Application.DisplayAlerts = False 
  If WasOpened2 Then Workbooks(FilenameNoPath(FoundFiles(i))).Close False 
  Application.DisplayAlerts = True

Application.DisplayAlerts = False should suppress any and all alerts from excel. Furthermore, I'm led to believe that passing False to .Close should automatically not save changes on the workbook. Yet I still get a prompt. Any ideas?

Application.DisplayAlerts = False 应该抑制来自 excel 的任何和所有警报。此外,我相信将 False 传递给 .Close 应该不会自动保存对工作簿的更改。但是我仍然收到提示。有任何想法吗?

回答by James

I had the inkling that another Excel add-in that was running alongside could be causing the issue. Coworker suggested to wrap with code to suppress events. This worked:

我有预感,同时运行的另一个 Excel 加载项可能会导致此问题。同事建议用代码包装来抑制事件。这有效:

  Application.EnableEvents = False
  Application.DisplayAlerts = False
  If WasOpened2 Then Workbooks(FilenameNoPath(FoundFiles(i))).Close False 
  Application.DisplayAlerts = True
  Application.EnableEvents = True