Home » excel » excel – How do I save an XLSM file as an XLSX file without prompting the user about lost data?

excel – How do I save an XLSM file as an XLSX file without prompting the user about lost data?

Posted by: admin April 23, 2020 Leave a comment

Questions:

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?


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). So far, so good. I’ll use 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. I’ve also recorded the same action with the MacroRecorder that also seems unable to skip the upcoming prompt.

My last try was a copy of the content using ThisWorkbook.Sheets.Copy and trying to remove the VBProject data. Tried various ways but it seems that the vb-project data can’t be really removed. After executing remove and stuff like that the debugger shows always three items of 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

How to&Answers:

You can use

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. Use the xlsx extension to make sure you don’t copy the macros.