简体   繁体   English

如何在不提示用户丢失数据的情况下将XLSM文件另存为XLSX文件?

[英]How do I save an XLSM file as an XLSX file without prompting the user about lost data?

TLDR : TLDR

How do I save a Excel-File-with-Macros as an Excel-File-without-Macros using VBA suppressing the prompt that the target format does not support macros ? 如何使用VBA 抑制目标格式不支持宏的提示,将带有宏的Excel文件另存为没有宏的Excel文件?


I have a xlsb file (Excel 2007+ with Macros), inside is the content and a button that should save that file as an xlsx (Excel 2007 WITHOUT Macros). 我有一个xlsb文件(带有宏的Excel 2007+),里面是内容和应该将该文件另存为xlsx的按钮(Excel 2007 WITHOUT Macros)。 So far, so good. 到目前为止,一切都很好。 I'll use ActiveWorkbook.SaveAs FileName:=name, FileFormat=xlOpenXMLWorkbook, Password="xyz" 我将使用ActiveWorkbook.SaveAs FileName:=name, FileFormat=xlOpenXMLWorkbook, Password="xyz"

But that always generates a prompt that tells the user that saving data in the target format means loosing the macro data and if he/she wants to continue... 但这总是会产生提示,告诉用户以目标格式保存数据意味着丢失宏数据以及他/她是否要继续...

I've tried Application.DisplayAlerts = False and ThisWorkbook.CheckCompatibility = False . 我已经尝试过Application.DisplayAlerts = FalseThisWorkbook.CheckCompatibility = False I've also recorded the same action with the MacroRecorder that also seems unable to skip the upcoming prompt. 我还用MacroRecorder记录了相同的动作,似乎也无法跳过即将出现的提示。

My last try was a copy of the content using ThisWorkbook.Sheets.Copy and trying to remove the VBProject data. 我的最后尝试是使用ThisWorkbook.Sheets.Copy内容的副本,并尝试删除VBProject数据。 Tried various ways but it seems that the vb-project data can't be really removed. 尝试了各种方法,但似乎无法真正删除vb-project数据。 After executing remove and stuff like that the debugger shows always three items of vb-project-data. 执行remove和类似的操作后,调试器将始终显示三项vb-project-data。

I'll check this tomorrow, but it looks very much like the code I've tried... Macro to save active Sheet as new workbook, ask user for location and remove macros from the new workbook 我明天会检查一下,但是看起来很像我尝试过的代码... 宏,用于将活动工作表另存为新工作簿,询问用户位置并从新工作簿中删除宏

You can use 您可以使用

Thisworkbook.SaveCopyAs ([filename.xlsx]) . Thisworkbook.SaveCopyAs ([filename.xlsx])

This creates a copy of the workbook without the macros in it and without the alert. 这将创建工作簿的副本,其中没有宏,也没有警报。 [filename.xlsx] should of course be replaced by your own file path. [filename.xlsx]当然应该替换为您自己的文件路径。 Use the xlsx extension to make sure you don't copy the macros. 使用xlsx扩展名确保您不复制宏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM