使用VBA将包含Excel文件(.xlsm)的宏另存为不包含文件(.xlsx)的宏时取消对话框 [英] Suppress dialog when using VBA to save a macro containing Excel file (.xlsm) as a non macro containing file (.xlsx)

查看:2121
本文介绍了使用VBA将包含Excel文件(.xlsm)的宏另存为不包含文件(.xlsx)的宏时取消对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您以这种格式保存文件,如何隐藏显示"Visual Basic宏的对话框".您确定要使用这种格式吗?" (请参见下图).

本质上,我正在尝试使用宏将.xlsm文件另存为.xslx文件吗?我已经尝试了所有可以找到的对话框抑制代码,但无法正常工作.

这是我的代码:

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

以下是对话框:

您可能会想像,我需要转换许多工作簿,并且不希望手动进行此操作.

-D.

解决方案

Application.DisplayAlerts = False是禁用此对话框的正确语句.但是,正如您所经历的那样,这在Excel 2011上不起作用.可悲的是,当您使用Excel 2011时,没有办法解决此问题.如果您在PC上使用任何其他版本,它都可以正常工作./p>

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).

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.

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.

解决方案

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.

这篇关于使用VBA将包含Excel文件(.xlsm)的宏另存为不包含文件(.xlsx)的宏时取消对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆