使用 VBA 将包含 Excel 文件 (.xlsm) 的宏保存为非宏包含文件 (.xlsx) 时抑制对话框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19328089/
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
Suppress dialog when using VBA to save a macro containing Excel file (.xlsm) as a non macro containing file (.xlsx)
提问by D. Woods
How do I suppress the dialog that says "Visual Basic macros will be removed if you save the file in this format. Are you sure you want to use this format?" (see picture below).
如何取消显示“如果您以此格式保存文件,将删除 Visual Basic 宏。您确定要使用此格式吗?”的对话框。(见下图)。
Essentially, I'm trying to use a macro to save a .xlsm file as an .xslx file?. I've tried all the dialog suppression code I can find and it isn't working.
本质上,我正在尝试使用宏将 .xlsm 文件保存为 .xslx 文件?。我已经尝试了我能找到的所有对话框抑制代码,但它不起作用。
Here's my code:
这是我的代码:
Private Sub SaveWithNoMacros()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
ActiveWorkbook.SaveAs Filename:="Clean Workbook With No Macros.xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Application.EnableEvents = True
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Here's the dialog:
这是对话框:
As you might imagine, I need to convert a lot of workbooks and would prefer not to do this manually.
正如您想象的那样,我需要转换大量工作簿,并且不想手动执行此操作。
-D.
-D。
回答by Netloh
Application.DisplayAlerts = False
is the correct statement to disable this dialog. But, as you have experienced, this does not work on Excel 2011. Sadly, there is no way to get around this when you use Excel 2011. Were you using any other version (on a PC) it would have worked just fine.
Application.DisplayAlerts = False
是禁用此对话框的正确语句。但是,正如您所经历的,这在 Excel 2011 上不起作用。遗憾的是,当您使用 Excel 2011 时无法解决这个问题。如果您使用任何其他版本(在 PC 上)它会工作得很好。
回答by Chris
This worked for me
这对我有用
Save as Type: (choose =>) Excel Macro-Enabled Workbook (*.xlsm)
另存为类型:(选择 =>)Excel 启用宏的工作簿 (*.xlsm)