The VBA editor opens through the Developer tab, which you must enable first
The Visual Basic for Applications editor in Excel does not appear by default. You need to turn on the Developer tab in the ribbon, then click the Visual Basic button. The process takes less than a minute and works the same way in Excel 2016, 2019, 2021, and Microsoft 365.
Once the Developer tab is visible, you will see the Visual Basic button in the Code group. Clicking it opens a separate window where you can write, edit, and test macros. This window is called the VBA IDE — the Integrated Development Environment.
Key Takeaways
- Enable the Developer tab by going to File > Options > Customize Ribbon, then checking the Developer box.
- Click Developer > Visual Basic to open the VBA editor window.
- The Project Explorer panel on the left shows your workbook structure; the code editor in the middle is where you write macros.
- You can also open the VBA editor by pressing Alt+F11 on Windows or Fn+Option+F11 on Mac.
- Save your macro-enabled file as .xlsm, not .xlsx, or your code will be lost when you close the file.
Enable the Developer tab in the ribbon
The Developer tab is hidden by default in Excel. To show it, click File in the top-left corner, then select Options at the bottom of the menu. In the Excel Options window, click Customize Ribbon on the left side.
In the right panel under Main Tabs, scroll down and find Developer. Check the box next to it, then click OK. The Developer tab now appears in your ribbon between Data and Help (or in a different position depending on your other tabs).
On Mac, the process is slightly different. Click Excel in the menu bar, select Preferences, then click Ribbon & Toolbar. Check the Developer box and close the window.
Open the VBA editor from the Developer tab
Once the Developer tab is visible, click it to see the Code group. The Visual Basic button is the first button in that group. Click it, and the VBA editor window opens in front of your spreadsheet.
The keyboard shortcut is faster if you use VBA regularly. Press Alt+F11 on Windows, or Fn+Option+F11 on Mac. This opens the editor instantly without clicking through the ribbon.
Understand the VBA editor layout
The VBA editor window has three main sections. On the left is the Project Explorer, which shows your workbook name and the sheets it contains. Each sheet is listed under VBAProject, along with a Modules folder where your code lives.
In the middle is the code editor itself — a blank text area where you write VBA code. When you select a sheet or module in the Project Explorer, its code appears here. At the bottom is the Immediate Window, which shows output from your code and lets you test commands one at a time.
Above the code editor are two dropdown menus. The left one shows the object you are working with (like a sheet name or UserForm). The right one shows the event or subroutine you are editing. These dropdowns help you navigate between different parts of your code.
Create your first macro in the editor
To write a new macro, right-click Modules in the Project Explorer and select Insert Module. A new module appears, and the code editor shows a blank space. Type Sub HelloWorld() and press Enter. The editor automatically adds End Sub below it.
Between those two lines, type MsgBox "Hello, Excel". This line tells Excel to display a message box with the text "Hello, Excel". To run the macro, press F5 or click the green play button in the toolbar. A small window pops up showing your message.
This simple macro demonstrates the basic structure: every macro starts with Sub and a name, contains code in the middle, and ends with End Sub. You can run any macro from the editor by selecting it and pressing F5.
Save your file as macro-enabled
Excel files normally use the .xlsx format, which cannot store VBA code. If you save a file with macros in .xlsx format, the code is deleted when you close the file. You must save it as .xlsm instead.
Click File > Save As. In the Save As dialog, click the dropdown that says "Excel Workbook (.xlsx)" and select "Excel Macro-Enabled Workbook (.xlsm)". Give your file a name and click Save. Your macros are now preserved.
If you forget and save as .xlsx, Excel warns you that the file contains features that will be lost. Click No, then use Save As to switch to .xlsm format.
Close the editor and return to your spreadsheet
Click the X button in the top-right corner of the VBA editor window to close it. You return to your normal Excel spreadsheet. Your macros remain in the file and run when you trigger them — either by pressing a keyboard shortcut, clicking a button, or calling them from another macro.
You can open the editor again at any time by pressing Alt+F11 or clicking Developer > Visual Basic. The code you wrote stays in the file as long as you saved it as .xlsm.
Frequently Asked Questions
What is the difference between a macro and VBA code?
A macro is a recorded or written sequence of actions that Excel performs automatically. VBA is the programming language you use to write those actions. When you write code in the VBA editor, you are writing a macro. The terms are often used interchangeably.
Can I run a macro without opening the VBA editor?
Yes. Once a macro is written and saved, you can run it by pressing its keyboard shortcut, clicking a button you assign to it, or calling it from another macro. You only need the editor to write or edit the code.
Why does my Developer tab not appear after I enable it?
Close Excel completely and reopen it. Sometimes the ribbon does not refresh immediately. If it still does not appear, go back to File > Options > Customize Ribbon and verify the Developer box is checked. On Mac, restart Excel after enabling it.
What happens if I close the editor without saving?
Any code you wrote in the current session is saved automatically to your .xlsm file. Excel saves the code when you close the editor or when you save the workbook itself. You do not need to save separately inside the editor.
Can I use the VBA editor in Excel Online?
No. The VBA editor is only available in the desktop version of Excel for Windows and Mac. Excel Online does not support VBA or macros. You must use the desktop application to write or edit code.