Struggling to save as xlsx file in VBA

六月ゝ 毕业季﹏ 提交于 2020-01-01 05:42:35

问题


Im new to VBA so any help is appreciated. Im having a problem with my SaveFile sub. This actually allows me to save the file but when I try to open it again Excel doesn't recognize it as an Excel file. In fact 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 stuff but cant get this file to save as just an xlsx format. I was able to get a macro-enabled excel file to work properly but that's not what I want. My code is below. Please ask questions if its not clear!

Thanks for your help.

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


回答1:


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


来源:https://stackoverflow.com/questions/37570620/struggling-to-save-as-xlsx-file-in-vba

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!