Method 1 – Save a VBA Code with an Excel Workbook
You can save the full workbook with macros. But you have to use another format to keep the macros. For macro-enabled workbook, the format is .xlsm and the format for normal Excel workbook is .xlsx or .xls. To save an Excel file as a macro-enabled workbook,
- Go to the File menu and select Save As.
- Go to the target location to save and give the file a suitable name.
- Click on the drop-down menu of the type option.
- Select the “Excel Macro-Enabled Workbook (*,xlsm)”
- Click Save.
Read More: How to Remove Macros from Excel
Method 2 – Save a VBA Code from Visual Basic Editor
- After the completing the module, go to the top ribbon and click on the File tab.
- Select Save, or press Ctrl + S, to save the file.
- A window named “Save As” will appear. Enter a name for the file in the File Name option.
- Click on the arrow in the Save as Type option to open the drop-down menu.
- From the drop-down menu, select the option “Excel Macro-Enabled Workbook (*,xlsm)”.
- Click OK to save the module with the workbook in Macro-Enabled Excel format.
Read More: How to Save Macros in Excel Permanently
Method 3 – Export VBA Code as BAS Format
You can save the VBA code individually by exporting it as a .bas file. You can then import it to another workbook to reuse the VBA code.
STEPS:
- After completing the module, go to File > Export File. You can also use shortcut keys are Ctrl + E.
- The “Export File” window will appear.
- Enter a suitable name for the module.
- You will see that the file format is “Basic Files”. Keep it as it is.
- Click on Save.
Read More: How to Edit Macros in Excel
Related Articles
- Using Macro Recorder in Excel
- How to Record a Macro in Excel
- Excel Macro Shortcut Key
- 25 VBA Macro Example for Enhanced Productivity
- Types of VBA Macros in Excel
- How to Use Excel VBA to Run Macro When Cell Value Changes
- Excel VBA to Pause and Resume Macro
- Excel Macro Enabled Workbook