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.

Beginner 14 min read

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

  1. Right-click any tab on the ribbon (for example Home) and choose Customize the Ribbon.... You can also go to File > Options > Customize Ribbon.
  2. In the list on the right, tick Developer.
  3. Click OK.

On a Mac

  1. Open the Excel menu and choose Preferences... (on newer versions Settings...).
  2. Click Ribbon & Toolbar.
  3. In the Main Tabs list, tick Developer and click Save.

The new tab appears between View and Help. Its most important buttons are:

ButtonWhat it does
Visual BasicOpens the VBA editor (Alt+F11, Mac: Opt+F11 or Fn+Opt+F11)
MacrosLists the macros you can run, edit or delete (Alt+F8, Mac: Opt+F8)
Record MacroStarts the macro recorder (see the next lesson)
Use Relative ReferencesMakes the recorder record positions relative to the active cell
Macro SecurityOpens the Trust Center macro settings from What is VBA? Macros, when to use them and macro security
InsertAdds buttons, check boxes and other controls to a sheet
Tip. You do not strictly need the Developer tab: Alt+F11 opens the editor and Alt+F8 opens the macro list from anywhere. But the tab makes the record button and the form controls one click away, so turn it on.

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:

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.

Note. Each worksheet shows two names in the Project Explorer, for example 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:

VBA
?Application.Version
?ActiveSheet.Name
?Range("A1").Address
Range("B2").Value = "Hello from the Immediate window"
?2026 * 12
Type these lines in the Immediate window and press Enter after each

A 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:

  1. In the Project Explorer, click the project of the workbook you want (make sure it is not PERSONAL.XLSB unless you mean it).
  2. Choose Insert > Module.
  3. A new Module1 appears 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.

VBA
Option Explicit

Sub ShowToday()
    ' Show today's date in a message box
    MsgBox "Today is " & Format(Date, "dddd d mmmm yyyy")
End Sub
Your first piece of code in a standard module

As you type you will notice several helpers:

  • Auto-capitalisation: type msgbox and when you leave the line it becomes MsgBox. 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 MsgBox a 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.

Tip. The red pop-up on every typing mistake can be annoying. In Tools > Options > Editor untick Auto Syntax Check. The line still turns red, but without the dialog box. Leave Require Variable Declaration ticked; it adds 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:

SettingSuggested valueWhy
Auto Syntax CheckOffRed lines are enough, no dialog interruptions
Require Variable DeclarationOnAdds Option Explicit to new modules
Auto List MembersOnIntelliSense lists after a dot
Auto Quick InfoOnShows the arguments of commands
Tab Width4Matches the indentation used in this course

Moving around and saving

A few keyboard shortcuts make the editor much quicker to use:

Shortcut (Windows)MacWhat it does
Alt+F11Opt+F11Switch between Excel and the editor
F5Fn+F5Run the macro the cursor is in
F8Fn+F8 or Cmd+Shift+IStep through the macro one line at a time
Ctrl+RCmd+RShow the Project Explorer
F4Fn+F4Show the Properties window
Ctrl+GCtrl+Cmd+GShow the Immediate window
Ctrl+SpaceCtrl+SpaceComplete the word you are typing
Ctrl+SCmd+SSave 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 .bas text 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 .bas file 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:

  1. Press Alt+F11 to open the editor.
  2. Insert a module and rename it modPractice in the Properties window.
  3. Type the macro below, click inside it and press F5.
  4. Switch back to Excel with Alt+F11 and look at Sheet1.
VBA
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
Writes a small staff list and reports in the Immediate window
AB
1NameDepartment
2Maria LopezSales
3Tom BeckerFinance
4Aiko TanakaIT

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 Sheet1 instead of Module1, 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 unqualified Range refers to that sheet, not the active one). Keep sheets and ThisWorkbook for 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 Explicit and module-level variables may sit above the first Sub. A statement like MsgBox "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?

2. Where should an ordinary macro such as FillStaffList be written?

3. What does typing ?ActiveSheet.Name in the Immediate window and pressing Enter do?

4. Which editor option adds Option Explicit to every new module?

5. How do you move a module to another open workbook most quickly?