Reputation: 1141
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 ?
Sub saveAsXlsx()
Dim myPath As String
myPath = Application.ActiveWorkbook.Path
Worksheets(Array("sheet1", "sheet2")).Copy
ActiveWorkbook.SaveCopyAs Filename:=myPath & "\Myfile.xlsx"
End Sub
Upvotes: 1
Views: 12311
Reputation: 96753
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 SaveAs rather than SaveCopyAs since you already have created the first copy.
Upvotes: 2