简体   繁体   English

Excel中的SaveAs FileFormat参数不依赖于版本

[英]SaveAs FileFormat argument in Excel isn't version-dependent

Starting in Excel 2007 it is recommended that you provide a FileFormat argument to the Workbook.SaveAs command because even if you specified a .xls filename but without a FileFormat argument, it will make the file corrupt and unable to be read in Excel 2003 since the newly saved file will take the format of the ActiveWorkbook (which would be 2007). 从Excel 2007开始,建议您为Workbook.SaveAs命令提供FileFormat参数,因为即使您指定了.xls文件名但没有FileFormat参数,它也会使文件损坏并且无法在Excel 2003中读取,因为新保存的文件将采用ActiveWorkbook的格式(将是2007)。

In order to save in Excel 2003 compatible format, it is suggested to use these following FileFormat values: - 4143 if in Excel 2003 and 56 in Excel 2007 as so: 为了保存Excel 2003兼容格式,建议使用以下FileFormat值: - 4143,如果在Excel 2003中, 56在Excel 2007中,如下:

If Val(Application.Version) < 12 Then
  ' You use Excel 97-2003
  FileExtStr = ".xls": FileFormatNum = -4143
Else
  ' you use excel 2007 or later
  FileExtStr = ".xls": FileFormatNum = 56
End If

However i tried using -4143 regardless if the executing client was Excel 2003 or 2007 and it worked fine. 但是,我尝试使用-4143,无论执行客户端是Excel 2003还是2007,它运行正常。 Can anyone confirm if this is the case? 任何人都可以确认是否是这种情况?

Source: Use VBA SaveAs in Excel 2007-2010 来源: 在Excel 2007-2010中使用VBA SaveAs

If you're using Excel 2003 to save a 2003 format file, then there's no need to specify the file format at all, since the default would be to save 2003 format anyway. 如果您使用Excel 2003保存2003格式文件,则根本不需要指定文件格式,因为默认情况下将保存2003格式。 The Application.Version code in the question works fine -- but no need to specify the FileFormat. 问题中的Application.Version代码工作正常 - 但不需要指定FileFormat。

Unless you're using the 2007 document converters in 2003, in which case I don't know how 2003 would play that card, but I expect it'll choose the default (56) unless you specify otherwise. 除非你在2003年使用2007年的文档转换器,在这种情况下我不知道2003年将如何使用该卡,但我希望它会选择默认值(56),除非你另有说明。

NB: I certainly can't specify xlFileFormat.xlExcel8 in 2003, as suggested above, so that's not much help. 注意:我当然不能在2003年指定xlFileFormat.xlExcel8,如上所述,所以没有多大帮助。

我建议显式使用xlFileFormat.xlExcel8 ,如果你想获得二进制.xls文件,则等于56。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM