如何在 Excel-VBA 中避免保存 MessageBox 提示?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6824816/
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:17  来源:igfitidea点击:

How to avert the save MessageBox prompt in Excel-VBA?

vbaexcel-vbaexcel-2007excel

提问by Vivian

I have a problem here if you look at my codes below after I call the .closeline which was the file I initially copied from. It will prompt a save MessageBox message either yes, no, or cancel. Is there anyway I can avoid this save message from appearing programmatic if no was the case could I just programmatic program it noinstead?

如果您在调用.close我最初从中复制的文件的行之后查看下面的代码,我会遇到问题。它将提示保存 MessageBox 消息是、否或取消。无论如何,我是否可以避免此保存消息以编程方式出现,如果不是这样,我可以no改为以编程方式对其进行编程吗?

回答by datatoo

Jon is right to suggest Application.DisplayAlerts and if you want to answer no to a save as you suggest

Jon 建议 Application.DisplayAlerts 是正确的,如果您想按照您的建议回答不保存

 Workbooks(Filename1).Close SaveChanges:=False

回答by Jon Raynor

Try setting the Application.DisplayAlerts to false, then closing. I recommend turning it back on after setting it.

尝试将 Application.DisplayAlerts 设置为 false,然后关闭。我建议在设置后重新打开它。

Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True

回答by RBarryYoung

IIRC:

国际研究中心:

Workbooks(FileName1).Save

If you save it explicitly, it won't have to ask you.

如果您明确保存它,它就不必询问您。