After making a macro in Excel, it is necessary to save the file. Also, you may want to save the macro module individually so you can use them in other files also. For this, you may want to learn how to save VBA code in Excel. But saving them is not as like saving a normal Excel file. So, in this article, I will show you some easy methods to save VBA code in Excel.
How to Save VBA Code in Excel: 3 Suitable Methods
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. So, to save an Excel file as a macro-enabled workbook follow the steps below:
📌 STEPS:
- Firstly, after working on the file, go to the File menu and select Save As option.
- Now, go to the target location to save and give the file a suitable name.
- Then, press on the drop-down menu of the type option.
- And, select the “Excel Macro-Enabled Workbook (*,xlsm)” option.
- Finally, press the Save button
Read More: How to Remove Macros from Excel
2. Save a VBA Code from Visual Basic Editor
Alternatively, you can save the macro modules with the workbook from the Visual Basic Editor. Follow the steps below to save the VBA macro from the visual basic editor.
📌 STEPS:
- After the completion of the module, go to the top ribbon, and press on the File tab.
- Then, select the Save option. Alternatively, you can press Ctrl + S to save the file.
- As an outcome, a window named “Save As” will appear. Give a suitable name for the file in the File Name option.
- Then, press on the arrow in the Save as Type option to open the drop-down menu.
- And, from the drop-down menu, select the option “Excel Macro-Enabled Workbook (*,xlsm)”.
- Finally, press OK to save the module with the workbook in Macro-Enabled Excel format.
Read More: How to Save Macros in Excel Permanently
3. Export VBA Code as BAS Format
You can save the VBA code individually by exporting it to the .bas file. And by doing this, you can import it to another workbook to reuse the VBA code. So, follow the steps below.
📌 STEPS:
- After the completion of the module, go to the top ribbon.
- Then, Select File > Export File
- Alternatively, press the Ctrl + E keys on the keyboard to do the same thing.
- Then, the “Export File” window will appear.
- Now, give a suitable name for the module.
- You will see that the file format is “Basic Files”. Keep it as it is.
- Finally, press the OK button.
- From the same location, you can import the module to re-use.
Read More: How to Edit Macros in Excel
Conclusion
In this article, I have shown 3 easy methods to save VBA code in Excel. I believe after reading this article, all confusion regarding this topic will be solved. So, I hope you found this article helpful. If you have any queries or recommendations, please share them in the comments section below. Keep learning new methods and keep growing!
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