防止 VBA 中的覆盖警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25739577/
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
Prevent Overwrite Warning in VBA
提问by Spionred
I am writing a macro to extract XML data from a Web API into a spreadsheet. The first column contains two fields delimited with a comma so I have extended the macro to insert a column then run Text to Columns to split out the data.
我正在编写一个宏来将 XML 数据从 Web API 提取到电子表格中。第一列包含两个用逗号分隔的字段,因此我扩展了宏以插入一列,然后运行 Text to Columns 以拆分数据。
The macro works really well, but I get an annoying warning asking if I want to replace the data:
宏运行得非常好,但我收到一个烦人的警告,询问我是否要替换数据:
Is there a way to suppress the warning?
有没有办法抑制警告?
回答by Synoon
source: SolutionSite
来源:SolutionSite
To suppress the warnings:
要抑制警告:
Application.DisplayAlerts = False
To activate the warnings:
要激活警告:
Application.DisplayAlerts = True
回答by Jean-Fran?ois Corbett
Application.DisplayAlerts = False
Two important points from the documentation:
[...] when a message requires a response, Microsoft Excel chooses the default response.
[...] 当消息需要响应时,Microsoft Excel 会选择默认响应。
and
和
If you set [DisplayAlerts] to False, Microsoft Excel sets [it back] to True when the code is finished [...]
如果您将 [DisplayAlerts] 设置为 False,Microsoft Excel 会在代码完成后将 [返回] 设置为 True [...]
meaning you'll still have the standard "Do you want to save before closing?" etc. prompts during normal Excel use.
这意味着您仍将拥有标准“您想在关闭前保存吗?” 等正常使用Excel时的提示。