8

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

Community
  • 1
  • 1
yarz-tech
  • 284
  • 2
  • 6
  • 18

1 Answers1

13

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
Takit Isy
  • 9,688
  • 3
  • 23
  • 47
some_weired_user
  • 556
  • 1
  • 5
  • 15
  • 1
    Thanks Simon! It seems from this that FileFormat in SaveAs doesn't actually add an extension? Is it simply recognizing the FileFormat? – yarz-tech Jun 01 '16 at 14:22
  • 2
    Really useful link with numbers for extensions: https://learn.microsoft.com/en-us/office/vba/api/excel.xlfileformat – Teamothy Oct 07 '19 at 09:09