Excel VBA Editor: How to Open and Use It

VBA & macros · Updated November 3, 2026

Excel VBA Editor: How to Open and Use It

The Excel VBA Editor, also called the Visual Basic Editor or VBE, is the desktop window where you write, inspect, and debug Visual Basic for Applications code for an Excel workbook. In Excel for Microsoft 365 on Windows, open it with Alt+F11, or choose Developer > Visual Basic; if the Developer tab is missing, enable it through Excel Options.

What the VBA Editor is for

VBA is Excel’s built-in programming language for automating tasks and responding to workbook events. A macro might format a report, prepare a batch of worksheets, validate an entry, or move data between sheets. The VBE is the environment used to create and manage that code; it is separate from the worksheet grid, although it works with the workbook open in Excel.

The editor is not a spreadsheet formula bar, and VBA is not the same thing as Office Scripts. Formulas calculate values in cells, while VBA can control many parts of the desktop Excel application and react to events such as opening a workbook or changing a cell. Office Scripts are a separate automation option, primarily designed for Excel on the web and cloud workflows. A VBA project is stored inside a macro-enabled workbook or another VBA-enabled file, not in an ordinary .xlsx file.

How to open it in Excel

On Windows, press Alt+F11 to switch between Excel and the VBE. You can also open the editor from the ribbon: select Developer > Visual Basic. If Developer is not visible, right-click the ribbon, choose Customize the Ribbon, select the Developer check box in the list of main tabs, and click OK. In some layouts, the same setting is available from File > Options > Customize Ribbon.

On a Mac, use Developer > Visual Basic if the Developer tab is shown. To show it, open Excel > Settings (called Preferences in some older releases), choose Ribbon & Toolbar, and enable Developer. The keyboard shortcut can depend on the Mac keyboard and function-key settings; try Option+F11, or use the ribbon command if that shortcut does not work. Excel for the web does not provide the VBA editor: open the workbook in the desktop app to create, edit, or run VBA.

The VBE normally opens in a separate window. If the editor opens but its panes are missing, use the View menu to restore them. You can resize or dock the panes and arrange the VBE to suit the task. The editor’s appearance can vary somewhat by Excel version and operating system, but the central concepts—projects, code modules, and debugging—are the same.

Understanding the main panes

The VBE is easier to navigate once you know what each window represents. The most useful panes and commands include:

  • Project Explorer: Lists open VBA projects, usually one for each open workbook or add-in. Expand a project to see its worksheets, ThisWorkbook object, and modules. Press Ctrl+R on Windows to show Project Explorer.
  • Properties window: Shows editable properties for the currently selected object, such as a worksheet’s code name. Press F4 on Windows to show it. A worksheet’s code name is not necessarily the same as its visible sheet tab name.
  • Code window: Displays the code belonging to the selected module or object. Double-click an item in Project Explorer to open its code window.
  • Immediate window: Lets you inspect values and run short VBA statements while debugging. Open it with Ctrl+G on Windows, or select it from the View menu. For example, typing ?ActiveSheet.Name and pressing Enter displays the active sheet’s name.
  • Object Browser: Helps you browse Excel’s available objects, methods, properties, and constants. Press F2 on Windows to open it.

These shortcuts are Windows shortcuts; on a Mac, function keys and modifier combinations can vary with the keyboard and macOS settings. Menu commands are a reliable alternative. If a pane has been closed, choosing it again from View usually brings it back.

Where VBA code belongs

A VBA project contains different kinds of code containers. Choosing the right one matters because Excel runs event procedures only when they are placed in the appropriate object module.

  • Standard module: The usual home for reusable macros and procedures that you run manually. In the VBE, select the workbook project and choose Insert > Module.
  • Worksheet module: Holds event code associated with one particular worksheet, such as a procedure that responds when a cell changes. In Project Explorer, double-click that worksheet to open its code module.
  • ThisWorkbook module: Holds events tied to the workbook, such as code that runs when the workbook opens or closes.
  • Class module: Defines a custom object when a project needs more structured, reusable code.
  • UserForm: Provides a custom dialog interface, with controls such as buttons and text boxes, for collecting input or presenting options.

For example, a macro intended to run from the Macros dialog generally belongs in a standard module. A procedure named Worksheet_Change belongs in the relevant worksheet module; placing it in a standard module does not make it respond to worksheet changes. This distinction is a frequent source of confusion for new VBA users.

Writing and running a first macro

To try a basic macro, open the VBE, choose Insert > Module, and put the procedure in the new code window. This example displays the name of the active worksheet:

Sub ShowActiveSheetName()
    ' Display the active worksheet name.
    MsgBox "Active sheet: " & ActiveSheet.Name
End Sub

Return to Excel and save a copy of the workbook as an Excel Macro-Enabled Workbook (.xlsm) before running it. Select Developer > Macros, choose ShowActiveSheetName, and click Run. You can also run a procedure from the VBE with F5 when the cursor is inside it. On Mac, use the Developer ribbon or the VBE menus if the function-key shortcut behaves differently. A macro can alter or delete workbook data, and its actions cannot be reversed with Ctrl+Z, so test unfamiliar code on a copy.

Once the procedure works, you can assign a macro to a worksheet button or another supported control, or run it from the Macros dialog. A macro stored in a workbook is generally available when that workbook is open. The Personal Macro Workbook, named PERSONAL.XLSB, is another option for macros you want available across Excel sessions on the same computer, but it is a separate workbook and should be backed up if it contains valuable code.

Debugging and fixing errors

VBA errors are easier to diagnose when you distinguish syntax errors from errors that occur during execution. A missing End Sub, misspelled keyword, or unmatched parenthesis can prevent code from compiling. A runtime error occurs after execution begins—for example, code may refer to a worksheet name that does not exist. A logic error is different again: the code runs, but the result is not what was intended.

Useful VBE debugging tools include:

  • Compile: Use Debug > Compile VBAProject to check the project for compile errors. The command may be unavailable when there is nothing to compile.
  • Breakpoints: Click in the left margin beside a line, or select the line and press F9 on Windows. Execution pauses there so you can inspect what happens next.
  • Step Into: Press F8 on Windows to run code one line at a time. The highlighted line indicates the next statement to execute.
  • Immediate window: Use it to inspect expressions or test a short statement while execution is paused. For example, entering ?ActiveCell.Address displays the active cell’s address.
  • Locals and watches: These debugging windows can help track variable values as a procedure runs; open them from the VBE’s View menu.

Windows shortcuts may require the Fn key on keyboards that assign their function keys to media controls. On Mac, use the corresponding VBE menu commands if a function key is intercepted by macOS or the keyboard. When a macro stops with an error, read the message and note the highlighted line before changing code. The highlighted line often identifies where the problem surfaced, though the underlying cause may be an earlier value or assumption.

Saving, compatibility, and platform limits

Saving as .xlsm preserves VBA code in a workbook. Saving a workbook containing VBA as .xlsx removes its VBA project; Excel warns about this when the format cannot retain macros. An Excel add-in can use the .xlam format, while legacy macro-enabled workbooks may use other formats. If colleagues need to run the macro, confirm that they have desktop Excel and that their organization permits the relevant macro content.

Excel for the web can open and edit many workbook contents, but it cannot create, edit, or run VBA macros. Use desktop Excel for those tasks. Mac Excel supports VBA, but some Windows-specific features and integrations are not portable. In particular, ActiveX controls and Windows API calls are not supported in the same way on Mac. Code that relies on Windows file paths, external components, or a Windows-only application may need changes or may not work on Mac. Test cross-platform workbooks in the target desktop environments rather than assuming identical behavior.

Excel’s macro recorder can generate VBA for some actions, but it does not record every operation and may produce code that needs cleanup. It is useful for learning how Excel expresses a formatting or navigation task. The recorded code is still VBA and is subject to the same file-format, security, and platform considerations as code written by hand.

Macro security and safe use

VBA can make broad changes to a workbook and interact with files or other applications, so only run macros from sources you trust. Do not enable all macros simply to avoid a warning. In Windows desktop Excel, macro-related options are under File > Options > Trust Center > Trust Center Settings > Macro Settings. Organization policy can control these choices, and current Office protections may block macros in files considered to have come from the internet.

Practical safeguards include reviewing the code, checking who supplied the file, and testing on a separate copy. Avoid placing files in a trusted location unless you understand that files there may bypass some security checks. Digitally signed macros can help identify a publisher, but a signature is not a guarantee that code is harmless. If the workbook comes from an employer or school, follow its IT guidance instead of changing security settings yourself.

Frequently Asked Questions

How do I open the VBA Editor in Excel?
In desktop Excel for Windows, press Alt+F11 or select Developer > Visual Basic. On a Mac, use the Developer tab’s Visual Basic command; the keyboard shortcut can depend on function-key settings. Excel for the web does not include the VBA editor.

Why can’t I see the Developer tab?
It is hidden by default in some Excel installations. On Windows, right-click the ribbon, choose Customize the Ribbon, check Developer, and select OK. On Mac, use Excel > Settings > Ribbon & Toolbar and enable the tab.

Can I use VBA in Excel for the web?
No. Excel for the web can work with many workbook features, but VBA macros must be created, edited, and run in desktop Excel. Open the file in the desktop application to access its VBA project.

What file type keeps an Excel macro?
Save a macro-enabled workbook as .xlsm. The regular .xlsx format does not retain VBA code. If Excel warns that the selected format cannot save the project, choose a macro-enabled format if you need to keep the code.

Can a VBA macro be undone with Ctrl+Z?
Usually not. Running VBA clears Excel’s normal undo history, so Ctrl+Z cannot reliably reverse a macro’s changes. Save a separate copy before testing code, especially if it edits or deletes data.

Is the VBA Editor the same on Mac and Windows?
The core editor concepts are similar, and both desktop versions support VBA, but keyboard shortcuts and some supported features differ. Windows-only integrations such as ActiveX or certain API calls can prevent code from working on Mac. Use menu commands when shortcuts differ and test macros on every platform where they must run.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.