File type inconsistency using VBA to SaveAs

Steph77

Board Regular
Joined
Sep 18, 2014
Messages
119
Hi all

I'm getting an error message when I try to open a file I created with a macro. If I click "Yes" to continue the file opens normally, but the people I work for get skittish about this kind of thing so I'd rather they didn't get an error message when I release the code on them and they are creating their own files:

Code:
Filename2 = "Consolidated Tracker " & Format(Date, "dd-mm-yy") & ".xlsx"
Filepath = diaFolder.SelectedItems(1) & "\" & Filename2
Workbooks.Add

ActiveWorkbook.SaveAs Filename:=Filepath, FileFormat:=51

Workbooks("Consolidator.xlsm").Sheets("Consolidated Tracker").Range("A1:AX" & CopyLastRow).Copy
Workbooks(Filename2).Sheets("Sheet1").Range("A1:AX" & CopyLastRow).PasteSpecial xlPasteColumnWidths
Workbooks(Filename2).Sheets("Sheet1").Range("A1:AX" & CopyLastRow).PasteSpecial xlPasteFormats
Workbooks(Filename2).Sheets("Sheet1").Range("A1:AX" & CopyLastRow).Value = Workbooks("Consolidator.xlsm").Sheets("Consolidated Tracker").Range("A1:AX" & CopyLastRow).Value
 
Workbooks(Filename2).Sheets("Sheet1").Name = "Consolidated Tracker " & Format(Date, "dd-mm-yy")

Workbooks(Filename2).Sheets("Sheet2").Delete
Workbooks(Filename2).Sheets("Sheet3").Delete

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=Filepath, FileFormat:=51
Application.DisplayAlerts = True

The error message is:

"The file you are trying to open, 'Consolidated Tracker 22-09-14.xls' is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?"

I think it's to do with the fact it's an xls file with an xlsx structure, but I looked it up and FileFormat:=51 should give me an xlsx file, and I have specified .xlsx in the Filename2 variable. What am I missing?
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Does it really show a .xls extension in the message you get?
 
Upvote 0
Yep it saves it as .xls - confirmed through DOS shell dir command....

(I was getting the error on a manual open)
 
Upvote 0

Forum statistics

Threads
1,214,121
Messages
6,117,846
Members
448,782
Latest member
lepaulek

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