我正在使用命令保存文件
FilNam = "//drive/folder/Test"
File.SaveAs FileName:=FilNam, FileFormat:=51
File.SaveAs FileName:=FilNam, FileFormat:=52
Run Code Online (Sandbox Code Playgroud)
这是它的显示方式
但是我可以选择这个文件并用excel打开以查看其中的数据。我希望它显示为 en excel 文件。如何修复此错误。
正如评论中提到的,最好在命名文件时包含扩展名。在你的情况下:
51 is for Open XML Workbook (*.xlsx)
52 is for Open XML Workbook With Macros Enabled (*.xlsm)
Run Code Online (Sandbox Code Playgroud)
对于所有可能的文件类型,您可以查看MSDN 上的XlFileFormat 枚举页面。
Additionally, as mentioned by Jeeped, if you are saving on a Windows location, the extension in the filename is not absolutely necessary since it should default automatically to the extensions mentioned above. Now, from the style of filename that you are using, I guess that you are saving the file to a remote Unix location which is probably why the extension is not added automatically. It should be different if you were saving on your desktop.