Save an Excel XLSM as XLSX and Remove Controls with VBA
Question details
Create an XLSX copy of an XLSM workbook and remove its form and ActiveX controls before saving.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A user wants to automate a macro-free workbook export without retaining worksheet controls.
- Observed behavior
- The XLSM workbook can be copied and saved as XLSX, but its form and ActiveX controls need to be deleted from the copy first.
Save the XLSM workbook to a writable local folder and enable macros so you can run the export. Check that the folder does not already contain files named ExportTemp.xlsm or ExportedWorkbook.xlsx.
Remove controls from a workbook copy before saving it as XLSX
Use this VBA macro to export the workbook containing the macro while leaving the original XLSM open and unchanged.
The macro creates a temporary XLSM copy, opens it with macros disabled, and checks each worksheet's Shapes collection. It deletes form controls and ActiveX controls before saving the copy in XLSX format.
The XLSX file cannot retain VBA code. Excel may display a warning about removing features when saving the copy.
In Excel, open the source XLSM workbook, then select Developer > Visual Basic. In the editor, choose Insert > Module.
Paste the following code into the module: Sub ExportWithoutControls() Dim tempPath As String, outPath As String Dim wb As Workbook, ws As Worksheet Dim i As Long Dim oldSecurity As MsoAutomationSecurity Dim tempCreated As Boolean Dim errorMessage As String If ThisWorkbook.Path = "" Then MsgBox "Save the source workbook to a local folder first." Exit Sub End If tempPath = ThisWorkbook.Path & Application.PathSeparator & "ExportTemp.xlsm" outPath = ThisWorkbook.Path & Application.PathSeparator & "ExportedWorkbook.xlsx" If Dir$(tempPath) <> "" Or Dir$(outPath) <> "" Then MsgBox "Remove or rename the existing export files first." Exit Sub End If oldSecurity = Application.AutomationSecurity On Error GoTo ExportError ThisWorkbook.SaveCopyAs tempPath tempCreated = True Application.AutomationSecurity = msoAutomationSecurityForceDisable Set wb = Workbooks.Open(tempPath) Application.AutomationSecurity = oldSecurity For Each ws In wb.Worksheets For i = ws.Shapes.Count To 1 Step -1 If ws.Shapes(i).Type = msoFormControl Or _ ws.Shapes(i).Type = msoOLEControlObject Then ws.Shapes(i).Delete End If Next i Next ws wb.SaveAs Filename:=outPath, FileFormat:=xlOpenXMLWorkbook wb.Close SaveChanges:=False Set wb = Nothing Kill tempPath MsgBox "Exported: " & outPath Exit Sub ExportError: errorMessage = Err.Description On Error Resume Next Application.AutomationSecurity = oldSecurity If Not wb Is Nothing Then wb.Close SaveChanges:=False If tempCreated Then Kill tempPath On Error GoTo 0 MsgBox "Export failed: " & errorMessage End Sub
Place the cursor inside ExportWithoutControls and select Run > Run Sub/UserForm. Respond to any Excel format warning, then open ExportedWorkbook.xlsx from the source workbook's folder and check the worksheets.

Work with Excel workbooks in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface for opening and editing Excel files. Its format compatibility can make moving everyday workbook tasks from Microsoft Office straightforward; the Excel VBA export above should be run in Excel.

Frequently Asked Questions
Why does the macro delete shapes in reverse order?
Deleting an item changes the positions of remaining shapes in the collection. Looping from Shapes.Count down to 1 avoids skipping controls.
Will the XLSX file retain the workbook's VBA macros?
No. XLSX is a macro-free format, so VBA code is not retained when the copy is saved with FileFormat:=xlOpenXMLWorkbook.
Does this delete controls from the original XLSM?
No. SaveCopyAs creates a temporary copy, and the macro deletes controls from that opened copy before saving it as XLSX.
Why does the macro refuse to run when export files already exist?
It checks the source folder for ExportTemp.xlsm and ExportedWorkbook.xlsx to avoid overwriting them. Move or rename those files, then run ExportWithoutControls again.




