How to Save VBA Code in Excel (3 Suitable Methods)

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.

How to Save VBA Code in Excel

  • 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.

How to Save VBA Code in Excel

  • Finally, press the Save button

How to Save VBA Code in Excel

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.

How to Save VBA Code in Excel

  • 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.

from Visual Basic Editor

  • 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.

from Visual Basic Editor

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.

Exporting as BAS Format

  • 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.

Exporting the VBA Code as BAS Format

  • 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

Get FREE Advanced Excel Exercises with Solutions!
Osman Goni Ridwan
Osman Goni Ridwan

OSMAN GONI RIDWAN is a marine engineer who loves exploring Excel and VBA programming. Programming, to him, is a time-saving tool for efficiently managing data, files, and internet tasks. He is proficient in Rhino3D, Maxsurf, C++, MS Office, AutoCAD, Excel, and VBA and goes beyond the basics. Armed with a B.Sc in Naval Architecture & Marine Engineering from BUET, OSMAN has transitioned into the role of a content developer. Specializing in creating technical content exclusively centered around Excel... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo