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?
 

Some videos you may like

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,133
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Does it really show a .xls extension in the message you get?
 

Steph77

Board Regular
Joined
Sep 18, 2014
Messages
119
Yep it saves it as .xls - confirmed through DOS shell dir command....

(I was getting the error on a manual open)
 

Watch MrExcel Video

Forum statistics

Threads
1,123,139
Messages
5,599,951
Members
414,351
Latest member
james27

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
Top