Excel – How to save xlsm as xlsx

excelvbaxlsx

I have a xslm file. I want to save the file as xlsx and email.

I am able to SaveCopyAs it as xls file. If I try to save it as xlsx, it does get saved but when I open it, it gives an error.

ActiveWorkbook.SaveCopyAs Filename:=ActiveWorkbook.Path & "\MyFileName - " & Format(Date, "mm-dd-yyyy") & ".xlsx"

Excel cannot open the file '…path\MyFileName.xlsx' because the file format or file extension is not valid. Verify that file has not been corrupted and that file extension matches the format of the file

Best Answer

SaveCopyAs does not change the file-type.

You simply cannot save a .xlsm as .xlsx via SaveCopyAs.

EDIT

a workaround is to save a copy which then is changed in type while the old copy will be deleted like:

Dim wb As Workbook, pstr As String

pstr = ActiveWorkbook.Path & "\MyFileName - " & Format(Date, "mm-dd-yyyy") & ".xlsm"
ActiveWorkbook.SaveCopyAs Filename:=y

Set wb = Workbooks.Open(pstr)
wb.SaveAs Left(pstr, Len(pstr) - 1) & "x", 52
wb.Close False

Kill pstr