VBA course · Lesson 2 of 33
The Developer tab and the VBA editor
Show the Developer tab, open the Visual Basic Editor and learn its windows: Project Explorer, Properties, code window, Immediate window and modules.
Before you can write a single line of VBA you need two things: the Developer tab on the ribbon, which holds the macro buttons, and the Visual Basic Editor (often just called the VBE or "the editor"), which is the separate window where code is written. This lesson sets both up and gives you a guided tour, so that in the next lessons you always know where you are.
Showing the Developer tab
Excel hides the Developer tab by default because most people never need it. Switching it on is a one-time job; Excel remembers the choice.
On Windows
- Right-click any tab on the ribbon (for example Home) and choose Customize the Ribbon.... You can also go to File > Options > Customize Ribbon.
- In the list on the right, tick Developer.
- Click OK.
On a Mac
- Open the Excel menu and choose Preferences... (on newer versions Settings...).
- Click Ribbon & Toolbar.
- In the Main Tabs list, tick Developer and click Save.
The new tab appears between View and Help. Its most important buttons are:
| Button | What it does |
|---|---|
| Visual Basic | Opens the VBA editor (Alt+F11, Mac: Opt+F11 or Fn+Opt+F11) |
| Macros | Lists the macros you can run, edit or delete (Alt+F8, Mac: Opt+F8) |
| Record Macro | Starts the macro recorder (see the next lesson) |
| Use Relative References | Makes the recorder record positions relative to the active cell |
| Macro Security | Opens the Trust Center macro settings from What is VBA? Macros, when to use them and macro security |
| Insert | Adds buttons, check boxes and other controls to a sheet |
Opening the editor
Press Alt+F11 (Mac: Opt+F11; on some Mac keyboards Fn+Opt+F11), or click Developer > Visual Basic. A new window opens. It looks old-fashioned compared to the rest of Excel because it has hardly changed in twenty-five years, and that is good news: a tutorial written long ago still matches what you see.
Pressing Alt+F11 again switches back to Excel. The editor stays open in the background, and closing Excel closes it too.
A tour of the editor
The editor has several panes. If one is missing, you can bring it back from the View menu.
Project Explorer (Ctrl+R)
The pane at the top left is the Project Explorer. It shows one project for every open workbook, named like VBAProject (Sales2026.xlsm). Expand a project and you see folders:
- Microsoft Excel Objects: one entry for every worksheet, plus
ThisWorkbook. Each of these has its own code area, used for event code that runs when something happens to that sheet or workbook (Events: macros that run by themselves). - Modules: standard modules such as
Module1. This is where ordinary macros go. A new workbook has none until you insert one. - Forms: UserForms (custom dialog boxes, see UserForms: build a data-entry form in VBA).
- Class Modules: blueprints for your own objects (Class modules: build your own objects in VBA).
If you have used the macro recorder or have add-ins loaded, you may also see VBAProject (PERSONAL.XLSB) and projects for add-ins. Some are password protected; that is normal.
Properties window (F4)
Below the Project Explorer sits the Properties window. It lists the properties of whatever is selected: a module's name, a worksheet's name and visibility, a button's caption on a form. The most useful property for now is (Name): select Module1 and change (Name) to modSales so you can tell your modules apart later.
Sheet1 (Invoices). The first is the code name (changed in the Properties window), the one in brackets is the tab name users see. Users can rename the tab, but not the code name, which makes code names a safer way to refer to sheets. You will use this in Workbooks and worksheets in VBA.The code window
The large area on the right is the code window. Double-click a module or a sheet in the Project Explorer to open its code. Each module opens in its own code window; you can switch between them from the Window menu.
At the top of the code window are two drop-down lists. The left one (Object) and the right one (Procedure) let you jump to a procedure or create event procedures without typing their names. For a standard module the right-hand list shows every Sub and Function in it, which is handy once a module grows long.
Immediate window (Ctrl+G)
The Immediate window usually sits at the bottom. If you do not see it, press Ctrl+G (Mac: Ctrl+Cmd+G) or choose View > Immediate Window. It is a scratchpad where you can type one line of VBA and run it at once by pressing Enter. Try these, one at a time:
?Application.Version
?ActiveSheet.Name
?Range("A1").Address
Range("B2").Value = "Hello from the Immediate window"
?2026 * 12A line that starts with ? means "print the result here". ?Application.Version prints the Excel version number (16.0 for all modern versions). The line without a question mark is an action: switch to Excel and you will see the text in B2. The Immediate window is also where Debug.Print writes its output, which you will use constantly in Error handling and debugging in VBA.
Inserting your first module
Macros you write yourself belong in a standard module. To create one:
- In the Project Explorer, click the project of the workbook you want (make sure it is not PERSONAL.XLSB unless you mean it).
- Choose Insert > Module.
- A new
Module1appears under Modules and its empty code window opens.
Now type the following. Type it rather than paste it, and watch what the editor does as you go.
Option Explicit
Sub ShowToday()
' Show today's date in a message box
MsgBox "Today is " & Format(Date, "dddd d mmmm yyyy")
End SubAs you type you will notice several helpers:
- Auto-capitalisation: type
msgboxand when you leave the line it becomesMsgBox. If a keyword does not change case, you probably misspelled it. - IntelliSense: after you type a dot, for example
Range("A1")., a list of everything a range can do pops up. Keep typing to filter it and press Tab to accept. - Quick info: after
MsgBoxa yellow tooltip shows the arguments the command expects. The argument in bold is the one you are typing now. - Syntax checking: if you leave a line with a mistake, such as a missing closing quote, the line turns red and a message pops up.
To run the macro, click anywhere inside it and press F5 (Mac: Fn+F5 or the green Run button). A message box shows today's date. Click OK to return to the editor.
Option Explicit to every new module automatically, which the next tip explains.Option Explicit and the Options dialog
Open Tools > Options (Mac: Excel > Preferences inside the editor, or Tools > Options). On the Editor tab, turn on Require Variable Declaration. From then on every new module starts with the line Option Explicit, which forces you to declare each variable before you use it. That sounds like extra work, but it catches typing mistakes such as Totl instead of Total before your macro runs. All code in this course assumes it is switched on; Variables and data types: Dim, Option Explicit and scope explains it in depth.
Other settings worth knowing on the same dialog:
| Setting | Suggested value | Why |
|---|---|---|
| Auto Syntax Check | Off | Red lines are enough, no dialog interruptions |
| Require Variable Declaration | On | Adds Option Explicit to new modules |
| Auto List Members | On | IntelliSense lists after a dot |
| Auto Quick Info | On | Shows the arguments of commands |
| Tab Width | 4 | Matches the indentation used in this course |
Moving around and saving
A few keyboard shortcuts make the editor much quicker to use:
| Shortcut (Windows) | Mac | What it does |
|---|---|---|
| Alt+F11 | Opt+F11 | Switch between Excel and the editor |
| F5 | Fn+F5 | Run the macro the cursor is in |
| F8 | Fn+F8 or Cmd+Shift+I | Step through the macro one line at a time |
| Ctrl+R | Cmd+R | Show the Project Explorer |
| F4 | Fn+F4 | Show the Properties window |
| Ctrl+G | Ctrl+Cmd+G | Show the Immediate window |
| Ctrl+Space | Ctrl+Space | Complete the word you are typing |
| Ctrl+S | Cmd+S | Save the workbook (from inside the editor) |
Saving from the editor saves the whole workbook, exactly like saving in Excel. Remember the lesson from What is VBA? Macros, when to use them and macro security: the file must be .xlsm, or the code is thrown away.
Removing, exporting and importing modules
Right-click a module in the Project Explorer to see three useful commands:
- Remove Module1... deletes the module. Excel first offers to export it; say Yes if you might want it back.
- Export File... saves the module as a
.bastext file (forms become.frm, classes.cls). That is how you back up code or move it to another workbook. - Import File... (on the File menu) brings a
.basfile into the selected project.
Copying a module between two open workbooks is even simpler: drag it in the Project Explorer from one project onto the other.
A worked example: a tidy project
Let us put it together. Open a new workbook, save it as EditorPractice.xlsm, then:
- Press Alt+F11 to open the editor.
- Insert a module and rename it
modPracticein the Properties window. - Type the macro below, click inside it and press F5.
- Switch back to Excel with Alt+F11 and look at Sheet1.
Option Explicit
Sub FillStaffList()
' Headers
Range("A1").Value = "Name"
Range("B1").Value = "Department"
' Three staff members
Range("A2").Value = "Maria Lopez"
Range("B2").Value = "Sales"
Range("A3").Value = "Tom Becker"
Range("B3").Value = "Finance"
Range("A4").Value = "Aiko Tanaka"
Range("B4").Value = "IT"
' Report what happened in the Immediate window
Debug.Print "Staff list written to " & ActiveSheet.Name & " at " & Now
End Sub| A | B | |
|---|---|---|
| 1 | Name | Department |
| 2 | Maria Lopez | Sales |
| 3 | Tom Becker | Finance |
| 4 | Aiko Tanaka | IT |
Sheet1 after running FillStaffList
The Debug.Print line does not show anything in Excel; look in the Immediate window and you will find a line such as Staff list written to Sheet1 at 02/12/2026 10:14:31 (the date format follows your Windows settings).
Common mistakes
- Typing code into a sheet module by accident. If you double-click
Sheet1instead ofModule1, your macro lands in the sheet's code area. It still runs, but ordinary macros belong in standard modules, and sheet modules behave differently (for example, an unqualifiedRangerefers to that sheet, not the active one). Keep sheets andThisWorkbookfor event code. - Writing in the wrong project. With several workbooks open, check the title bar of the code window: it shows the workbook name, such as
EditorPractice.xlsm - modPractice (Code). - Code outside a procedure. Only declarations such as
Option Explicitand module-level variables may sit above the firstSub. A statement likeMsgBox "Hi"on its own outside a Sub gives "Invalid outside procedure". - Pressing F5 with the cursor outside any macro. The editor then shows the Macros dialog and asks which one to run. Click inside the procedure first.
Check yourself
1. Which shortcut opens the VBA editor on Windows?
Alt+F11 toggles between Excel and the editor. Alt+F8 opens the list of macros.
2. Where should an ordinary macro such as FillStaffList be written?
Standard modules hold general macros. Sheet modules and ThisWorkbook are meant for event code.
3. What does typing ?ActiveSheet.Name in the Immediate window and pressing Enter do?
A leading question mark prints the value of the expression that follows it.
4. Which editor option adds Option Explicit to every new module?
Require Variable Declaration (Tools > Options > Editor) inserts Option Explicit at the top of each new module.
5. How do you move a module to another open workbook most quickly?
Dragging a module between projects copies it. Export and Import also work for workbooks that are not open together.