vba 将 Xlsm 文件另存为 xlsx
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25888193/
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
Save Xlsm file as xlsx
提问by user1902849
I want to save the current xlsm file as xlsx, so i wrote a code as below. This code really done it job and i able to see the file saved as Myfile.xlsx as what i've defined in the code, however there is some small issues where the vba always save the file to another file as bookx.xlsx beside the Myfile.xlsx. How can i avoid this ?
我想将当前的 xlsm 文件保存为 xlsx,所以我编写了如下代码。这段代码确实完成了它的工作,我能够看到文件保存为 Myfile.xlsx 作为我在代码中定义的内容,但是有一些小问题,vba 总是将文件保存到另一个文件中作为 bookx.xlsx 旁边的我的文件.xlsx。我怎样才能避免这种情况?
Sub saveAsXlsx()
Dim myPath As String
myPath = Application.ActiveWorkbook.Path
Worksheets(Array("sheet1", "sheet2")).Copy
ActiveWorkbook.SaveCopyAs Filename:=myPath & "\Myfile.xlsx"
End Sub
回答by Gary's Student
This will avoid the extra copy:
这将避免额外的副本:
Sub saveAsXlsx()
Dim myPath As String
myPath = Application.ActiveWorkbook.Path
Worksheets(Array("sheet1", "sheet2")).Copy
ActiveWorkbook.SaveAs Filename:=myPath & "\Myfile.xlsx"
ActiveWorkbook.Close
End Sub
This uses SaveAsrather than SaveCopyAssince you already have created the first copy.
这使用SaveAs而不是SaveCopyAs,因为您已经创建了第一个副本。