Excel VBA:具有不同文件扩展名的 SaveCopyAs
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45455086/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel VBA: SaveCopyAs with different file extenstion
提问by Istvanb
I have an Excel file with .xlsb extenstion and use its macros to generate several other Excel sheets based on the contents. The macros work in a way that they change the original Excel file and then use the SaveCopyAs
method to save the generated Excel sheets.
我有一个扩展名为 .xlsb 的 Excel 文件,并使用其宏根据内容生成其他几个 Excel 工作表。宏的工作方式是更改原始 Excel 文件,然后使用该SaveCopyAs
方法保存生成的 Excel 工作表。
The generated Excel sheets should be saved with .xlsx extension and format.
生成的 Excel 工作表应以 .xlsx 扩展名和格式保存。
Using the ActiveWorkbook.SaveCopyAs"C:\TEMP\XXXX.XLSX" method is not working for me because while it does change the extension it does NOT change the file format so when a user opens a generated Excel file he receives a warning message (something like "the file extension and format does not match"). The SaveCopyAs
method does not have any other arguments.
使用ActiveWorkbook.SaveCopyAs"C:\TEMP\XXXX.XLSX" 方法对我不起作用,因为虽然它确实更改了扩展名,但它不会更改文件格式,因此当用户打开生成的 Excel 文件时,他会收到一条警告消息(类似于“文件扩展名和格式不匹配”)。该SaveCopyAs
方法没有任何其他参数。
How can I save the copies of my original .xlsb file with both the extension and format to be changed to .xlsx?
如何将扩展名和格式都更改为 .xlsx 的原始 .xlsb 文件的副本保存?
Note: the Workbook.SaveAsmethod does have a fileformat
option, not sure if that helps / relevant.
注意:Workbook.SaveAs方法确实有一个fileformat
选项,不确定这是否有帮助/相关。
采纳答案by Istvanb
Based on the hint by Zac, in my case its a better solution to copy the tab with the relevant changes into a freshly created excel file and then save it with the new filename.
根据 Zac 的提示,在我的情况下,将具有相关更改的选项卡复制到新创建的 excel 文件中,然后使用新文件名保存它是一个更好的解决方案。
ThisWorkbook.Sheets("myTab").Copy
ActiveWorkbook.SaveAs Filename:="c:\temp\xyz.xlsx", FileFormat:=51
ActiveWorkbook.Close
This is actually a lot better solution for me as the end user really need the generated tab only and not the macros or any other data in the orginal excel file.
这对我来说实际上是一个更好的解决方案,因为最终用户确实只需要生成的选项卡,而不是原始 excel 文件中的宏或任何其他数据。