VBA - Can't save .xlsm file to .xlsx - runtime error 1004

soundtrackz

New Member
Joined
Dec 8, 2023
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I have many macros with this and it suddenly stopped working - displaying runtime error 1004 - can't save from xlsm file to macro-free file.
Any idea, what happened?

VBA Code:
Sub Saving()
    Dim strName As String

    Application.DisplayAlerts = False
    
    strName = ThisWorkbook.Path & "\SomeName.xlsx"
    ThisWorkbook.SaveAs Filename:=strName, FileFormat:=xlOpenXMLWorkbook
    
    Application.DisplayAlerts = True
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Welcome to the Board!

You cannot save any file that contains Macros/VBA to an "xlsx" format, as that format does NOT allow Macros/VBA.
You will need to save it to a format that DOES allow Macros/VBA, like "xlsm" or "xlsb", and change the "FileFormat" argument.

Here is a listing of the different options. Make sure that the FileFormat and extension coincide:

For example, if electing to use "xlsm", it should look like:
Rich (BB code):
Sub Saving()
    Dim strName As String

    Application.DisplayAlerts = False
    
    strName = ThisWorkbook.Path & "\SomeName.xlsm"
    ThisWorkbook.SaveAs Filename:=strName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
    
    Application.DisplayAlerts = True
End Sub
 
Upvote 0
That code should work fine as long as the workbook with the code in it has been saved.
 
Upvote 0
You cannot save any file that contains Macros/VBA to an "xlsx" format, as that format does NOT allow Macros/VBA.

Well, I could until about 2 days ago, when I suddenly couldn’t.
Was there some change in policies or what?
 
Upvote 0
That code should work fine as long as the workbook with the code in it has been saved.
Of course, the workbook is saved.
It's driving me mad, because now I have to split everything into 2 files - one file with the code (.xlsm) and another .xlsx template.:)
 
Upvote 0
If you don't have any code in the worksheets, you could try just copying them and then saving the newly-created workbook.
 
Upvote 0
Of course, the workbook is saved.
It's driving me mad, because now I have to split everything into 2 files - one file with the code (.xlsm) and another .xlsx template.:)
I would double-check to make sure that there is no code in the "xlsx" one.
If you turned on the Macro Recorder at any point, you may have accidentally recorded some code in there.
Also note, not only do you need to remove all VBA code from the "xlsx" file, but also any VBA modules that were created (i.e Module1). Even empty VBA modules will cause Excel to think there is VBA code in there.
 
Upvote 0
It appears that the dialog box that Excel puts up in response to doing this has changed. Before, the default response (which is what is selected if you use DisplayAlerts = False) was Yes, which would allow saving. With the new dialog, the default response is now Go Back, which prevents the save.
 
Upvote 0
Interestingly I have no problem saving an xlsm file with code to an xlsx file, even though I've seen a number of posts about this.
So not sure why it only seems to affect some people.
 
Upvote 0
Which version/build are you on?
 
Upvote 0

Forum statistics

Threads
1,215,110
Messages
6,123,139
Members
449,098
Latest member
Doanvanhieu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top