How to Save a Copy as XLSX Using Excel VBA (5 Suitable Ways)

We have taken a simple and concise dataset that has 3 columns and 6 records of students’ marks to show how to save it as an XLSX file.

Suitable Ways to Save a Copy of Excel File as XLSX Using VBA


Method 1 – Using the SaveCopyAs Method

Steps:

  • Go to the Developer tab and select Visual Basic.

Suitable Ways to Save a Copy of Excel File as XLSX Using VBA

  • In the Visual Basic window, click on Insert and select Module.

Suitable Ways to Save a Copy of Excel File as XLSX Using VBA

  • In the new module window on the right, insert in the following code:
Sub SaveCopyAs_Method()
Application.DisplayAlerts = False
ActiveWorkbook.SaveCopyAs "C:\Users\USER\Desktop\5700\SaveCopyAs method.xlsx"
End Sub

Suitable Ways to Save a Copy of Excel File as XLSX Using VBA

  • Close the VBA window and navigate to the Developer tab again.
  • Select Macros.

  • In the Macro window, you should see the macro code we inserted.
  • Click on Run.

  • Open the folder where you saved the file, and it should be available in the XLSX format.

Read More: Create New Workbook and Save Using VBA in Excel


Method 2 – Specifying a Filename

  • Open a new VBA module (see Method 1 for exact steps).
  • Insert the below code in the VBA module window.
Sub Specify_file_name()
Dim location As String
location = "C:\Users\USER\Desktop\5700\Specify file name.xlsx"
ActiveWorkbook.SaveAs Filename:=location
End Sub

Suitable Ways to Save a Copy of Excel File as XLSX Using VBA

  • Run it from the Macros option as shown previously.
  • Go to the save folder and the file with the XLSX format should be there.

Read More: Excel VBA to Save Workbook in Specific Folder with Date


Method 3 – Entering a File Format Number

Our goal is to save an Excel copy as an XLSX file using VBA. We will use the format number 51, which denotes the XLSX file type.

  • Insert the following code in the VBA module:
Sub file_format_number()
Dim location As String
Application.DisplayAlerts = False
location = "C:\Users\USER\Desktop\5700\File format number"
ActiveWorkbook.SaveAs Filename:=location, FileFormat:=51
End Sub

Suitable Ways to Save a Copy of Excel File as XLSX Using VBA

  • If you run this code, Excel will immediately save the workbook in an XLSX format. You can confirm that by checking in the destination folder.

Read More: Excel VBA Save as File Format


Method 4 – Saving with a Password

  • Enter the below VBA code in the Module window:
Sub Save_With_Password()
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs _
Filename:="C:\Users\USER\Desktop\5700\Save with password.xlsx", Password:="one"
End Sub

Suitable Ways to Save a Copy of Excel File as XLSX Using VBA

  • Run this code from the Macros options.
  • If you go to your saved folder, you should find the file with the name that you gave and the XLSX extension at the end.


Method 5 – Save by Recommending Read Only

  • Insert the following code in the VBA module:
Sub recommend_read_only()
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs _
Filename:="C:\Users\USER\Desktop\5700\Recommend read only.xlsx", _
ReadOnlyRecommended:=True
End Sub

Suitable Ways to Save a Copy of Excel File as XLSX Using VBA

  • Run this code from the Macros option under the Developer tab. This should save an XLSX copy of the current workbook as shown below.

Read More: Excel VBA to Save File with Variable Name


Things to Remember

  • Make sure to change the saving path of the XLSX file in the VBA. It should match a folder path inside your computer.
  • Double-check to see that you are spelling all the built-in VBA functions exactly as I have done.
  • In some cases, the VBA code may not be available anymore in the VBA window after running the code.

Download the Practice Workbook


Related Articles

Get FREE Advanced Excel Exercises with Solutions!
Nazmul Hossain Shovon
Nazmul Hossain Shovon

Nazmul Hossain Shovon, a BUET graduate in Naval Architecture and Marine Engineering, embarked on his career with 8 months dedicated to the Exceldemy project's triumph. Transitioning into a Software Developer role, he specialized in web add-in development. At Exceldemy, he authored about 125 blog articles and solved many visitors’ problems, refining his writing skills and delving into Excel-related topics. With a primary passion for programming and software development, Shovon continually explores new horizons, fostering professional growth in his... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo