VBA error with saving and then opening .XLSM

DouglasWicker

New Member
Joined
Aug 8, 2017
Messages
38
Morning all,

I have this code below written to save my spreadsheet

Dim Path As String
Dim filename As String

Path = "Private File Path"
filename = Range("Y2") + Range("Y1")
ActiveWorkbook.SaveAs filename:=Path & filename & ".xlsm", FileFormat:=xlNormal


The issue I have is that the above code works fine to save an xls file but when I change it to xlsm, it seems to save fine but when I open it I get this error message?

Excel cannot open the file 'Filename.xlsm' because the file format or file extension is not valid. Verify that the file has not been corrupted and the file extension matches the format of the file.

It will open if I save it as an .xlsm file through excel's Save As function.

Any ideas?
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Guessing it's to do with you saving a .xlsm in file formal xlNormal, try FileFormat:=52 or xlOpenXMLWorkbookMacroEnabled
 
Upvote 0
@mrhstn is correct. Also you don't need the & ".xlsm" part, this is apended automatically when setting the fileformat

Code:
Dim Path As String
Dim filename As String


Path = "C:\Test\"
filename = "SaveAsTest2"
ActiveWorkbook.SaveAs filename:=Path & filename, FileFormat:=xlOpenXMLWorkbookMacroEnabled
 
Upvote 0
I'm having the problem saving to FileFormat:=xlOpenXMLWorkbookMacroEnabled
I'm running Excel 2019
I can save a blank workbook as .XLSM and open it, but not the VBA saved XLSM.

Anyone else encounter the same issue and what was the fix?
Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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