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

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.

How to Save VBA Code in Excel

  • 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)”

How to Save VBA Code in Excel

  • Click Save.

How to Save VBA Code in Excel

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.

How to Save VBA Code in Excel

  • 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 Visual Basic Editor

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

from Visual Basic Editor

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.

Exporting as BAS Format

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

Exporting the VBA Code as BAS Format

Read More: How to Edit Macros in Excel


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