Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save as xlsx file?

Tags:

excel

vba

save-as

My SaveFile sub saves the file but when I try to open it again Excel doesn't recognize it as an Excel file.

If I right click the file from my desktop and check the properties, the type of file is "File". I've read up on the formatting but can't get this file to save as an xlsx format. I was able to get a macro-enabled excel file to work properly but that's not what I want.

Sub SaveFile()

    MsgBox ("You will now be prompted to save your file") 'Notifies User 
    savename = Application.GetSaveAsFilename()  'Gets directory/name
    ActiveWorkbook.SaveAs Filename:=savename, FileFormat:=51 'Something is wrong 

End Sub

Here is the picture of the "Formatless" file
enter image description here

like image 904
yarz-tech Avatar asked Jun 01 '16 13:06

yarz-tech


People also ask

Is Excel and XLSX same?

XLSX is a zipped, XML-based file format. Microsoft Excel 2007 and later uses XLSX as the default file format when creating a new spreadsheet. Support for loading and saving legacy XLS files is also included. XLS is the default format used with Office 97-2003.


1 Answers

When saving the file you should save it with its extension:

Sub SaveFile()

    savename = Application.GetSaveAsFilename(fileFilter:="Exel Files (*.xlsx), *.xlsx") 
    ActiveWorkbook.SaveAs Filename:=savename, FileFormat:=51 

End Sub
like image 149
some_weired_user Avatar answered Oct 02 '22 04:10

some_weired_user