Can I save macro in XLSX format?

In Excel, you can save a file using the VBA code. You can do it by specifying the path and name of a file in code, or by opening Save As window.

In this tutorial, I’m going to show you both ways.

A quick way to save a file in VBA

You can quickly save an XLSX file using this single line of code. In this case, you have to give a path and file name where the program should save the file.

Sub saveFile()
    ActiveWorkbook.SaveAs Filename:="D:\temp\myFile.xlsx", FileFormat:=51
End Sub

In this code, the file name is given with the XLSX extension. You can drop it because there is specified the file format code: 51. This code means that the file will be saved in this format.

Open the SaveAs window

If you don’t want to place the name of the file in code each time you run the script, you can open a SaveAs window asking the user for the name and path.

Sub saveFile()
    save_name = Application.GetSaveAsFilename(fileFilter:="Excel File (*.xlsx), *.xlsx")
    ActiveWorkbook.SaveAs Filename:=save_name, FileFormat:=51
End Sub

This is the same window when you saving an Excel file for the first time or using Save As to choose a different name.

Can I save macro in XLSX format?

Display information after successful save

If you want to be sure that the file is saved correctly, you can display a box with the success message and file path of the file location.

Sub saveFile()
    save_name = Application.GetSaveAsFilename(fileFilter:="Excel File (*.xlsx), *.xlsx")
    ActiveWorkbook.SaveAs Filename:=save_name, FileFormat:=51
    If save_name <> False Then
        MsgBox "Save as " & save_name
    End If
End Sub

After you run the code, the Save As will appear. Save the file to display the message.

Can I save macro in XLSX format?

Post Views: 29,101

See all How-To Articles

In this tutorial, you will learn how to save a macro-enabled workbook in Excel and Google Sheets.

Can I save macro in XLSX format?

Save a Macro-Enabled Workbook (.xlsm)

In Excel you can create a macro, using the macro recorder. If you are working with standard Excel file type (.xlsx), save it as a macro-enabled workbook (.xlsm) to be able to use macros.

Note that this isn’t necessary with the old Excel type (.xls), as it’s already macro-enabled.

Create a Macro

Macros can help you to reduce repetitive work in Excel by recording a set of actions and repeating them by running the macro. To record a macro, follow these steps:

1. In the Ribbon, go to View > Macros > Record Macro.

Can I save macro in XLSX format?

2. In the Record Macro window, (1) enter a macro name and a (2) shortcut key, then (3) click OK.

Can I save macro in XLSX format?

3. Make changes in the sheet that should be performed by the macro (change in fonts, colors, sizes, etc.)

4. In the Ribbon, go to View > Macros > Stop Recording.

Can I save macro in XLSX format?

Save a File With the .xlsm Extension

Now save the file as macro-enabled to be able to use the recorded macro later.

1. In the Ribbon, go to File > Save As.

Can I save macro in XLSX format?

2. In the save window, select file type Excel Macro-Enabled Workbook (*.xlsm), and click Save.

Can I save macro in XLSX format?

Finally, the file is saved as macro-enabled, and you can use all macros recorded within it.

How do I enable macros in XLSX?

Change macro settings in the Trust Center.
Click the File tab..
Click Options..
Click Trust Center, and then click Trust Center Settings..
In the Trust Center, click Macro Settings..
Make the selections that you want, then click OK..

Can you save XLSM as XLSX?

All you have to do is drag and drop the XLSM file, select the desired format, and click on convert. When you are done converting the file, you can download the XLSX file. The files you are converting will be stored in Cloud.

Can VBA run in XLSX?

The answer is yes. You need just reference to . xlsx file.

Can macros be saved in any Excel file?

But what if you want to use the macro in other workbooks? To make your macros available every time you open Excel, you can create them in a workbook called Personal. xlsb. That's a hidden workbook stored on your computer, which opens in the background every time you open Excel.