When you create or record a Macro in Excel, the workbook must be saved in a format that can store VBA Macro code. A normal Excel workbook usually uses the .xlsx extension, while a macro-enabled workbook commonly uses the .xlsm extension.
A Macro-Enabled Workbook is an Excel workbook that can store VBA Macro code.
It is commonly saved using the .xlsm file extension.
This format is useful when you create Excel workbooks containing Macros or VBA programs.
The .xlsm extension identifies an Excel Macro-Enabled Workbook.
For example:
Student_Result.xlsm
This type of workbook can store VBA Macro code along with worksheet data and formatting.
The .xlsx format is a standard Excel workbook format.
It is commonly used for workbooks that do not need to store VBA Macro code.
For a workbook containing VBA Macros, you should use an appropriate Macro-enabled format.
| Extension | Workbook Type | Macro Support |
|---|---|---|
| .xlsx | Excel Workbook | Does not store VBA Macro code. |
| .xlsm | Excel Macro-Enabled Workbook | Can store VBA Macro code. |
A Macro-enabled format is required when you want to keep VBA Macro code inside the workbook.
If you save a Macro workbook in an inappropriate format, Excel can warn you that Macro functionality cannot be preserved.
To save a workbook in a Macro-enabled format, use the Save As command.
You can use:
File → Save As
This allows you to choose the file name, location, and file type.
In the Save As window, choose the folder where you want to store the workbook.
For example, you can save your practice workbook in a folder named Excel Macro Practice.
Enter a meaningful name for your workbook.
For example:
Student_Marksheet
Excel will add the selected file extension when the workbook is saved.
In the Save As window, locate the Save as type option.
Click the drop-down list to see the available Excel file formats.
From the file type list, select:
Excel Macro-Enabled Workbook (*.xlsm)
This tells Excel that the workbook should be saved in a format that supports VBA Macro code.
After selecting the Macro-enabled workbook format, click Save.
Excel will save the workbook using the selected file type.
When saving a workbook that contains features not supported by the selected format, Excel may display a warning message.
If you selected the Macro-enabled workbook format correctly, the workbook can store VBA Macro code.
Saving the workbook as .xlsm allows VBA Macro code to remain part of the workbook.
When you reopen the workbook, the Macro can be available according to the workbook and Excel security settings.
After saving a workbook as .xlsm, you can close it and open it again later.
The workbook can contain its worksheets, formatting, formulas, and VBA Macro code.
When a Macro-enabled workbook is opened, Excel's Macro Security settings determine how its VBA Macros are handled.
A security notification may appear when Macros are blocked.
Only enable Macros when you trust the workbook and understand its source.
Examples of Macro-enabled workbook names include:
Suppose you have recorded a Macro named:
FormatStudentData
To preserve the Macro, save the workbook as:
Student_Marksheet.xlsm
The workbook can then store the recorded Macro along with the worksheet data.
If a workbook contains VBA Macro code and you try to save it as a format that cannot preserve the Macro, Excel can display a warning.
The Macro code may not be retained if you continue with a format that does not support VBA Macros.
Therefore, choose .xlsm when you need to preserve VBA Macro code.
Save saves changes to the current workbook using its existing file format.
Save As allows you to create a saved version using a different file name, location, or file type.
When converting a workbook to a Macro-enabled format, Save As is commonly used to select the required file type.
While learning Excel VBA, it is useful to create a separate folder for Macro practice files.
For example:
Excel Macro Practice
├── Student_Marksheet.xlsm
├── Attendance_System.xlsm
└── Report_Generator.xlsm
Different Excel VBA projects can be saved as separate Macro-enabled workbooks.
For example, a student result project and an attendance project can each have their own .xlsm workbook.
After saving the workbook, check the file name to confirm that it uses the .xlsm extension when Macro support is required.
For example:
My_First_Macro.xlsm
It is a good practice to save your workbook before testing important Macro changes.
This helps ensure that your latest Macro code and workbook changes are stored.
When you edit VBA code in the Visual Basic Editor, save the workbook after making the required changes.
The Macro-enabled workbook format allows the VBA project to be stored with the workbook.
A common beginner mistake is saving a workbook containing VBA code in a file format that does not support VBA Macros.
Always check the file type when saving a workbook that contains Macro code.
Suppose you recorded a Macro called:
FormatStudentData
Use the following process:
The resulting file can be:
Student_Marksheet.xlsm
| Format | Extension | Purpose |
|---|---|---|
| Excel Workbook | .xlsx | Standard Excel workbook without VBA Macro storage. |
| Excel Macro-Enabled Workbook | .xlsm | Stores Excel workbook data and VBA Macro code. |
The complete workflow for saving a Macro-enabled workbook is:
A Macro-enabled workbook is used when an Excel workbook needs to store VBA Macro code. The common extension for this format is .xlsm.
To save a Macro-enabled workbook, use File → Save As and select Excel Macro-Enabled Workbook (*.xlsm).
Using the correct file format helps preserve the VBA Macro code inside the workbook so that it can be used again when the workbook is reopened.
Question: Which file format should normally be used to preserve VBA Macro code in an Excel workbook?