30 Advanced Excel Tips for 2026

Excel Champs / VBA / How to Open VBA Editor in Excel
By Puneet Gogia (Microsoft MVP)

How to Open VBA Editor in Excel

30+ Advanced Excel Tips for 2026

No spam. Only Excel Stuff. God Promise. 😊

Press Alt + F11 to open the Visual Basic Editor, and press it again to return to Excel. You can also click Developer → Visual Basic, or right-click a sheet tab and choose View Code. On a Mac, use Option + F11 or Fn + Option + F11.

If Alt + F11 does nothing, your laptop’s function keys may need Fn. Excel for the web, iPad and Android has no VBA editor.

Add code with Insert → Module. Standard modules hold macros you run yourself and functions you call from cells. Code that reacts to events, such as opening the file or changing a cell, goes in the ThisWorkbook or sheet module.

The windows you’ll use most are Project (Ctrl + R), Properties (F4), Immediate (Ctrl + G) and Object Browser (F2). Press F5 to run the procedure the cursor is in and F8 to step through it line by line.

Turn on Tools → Options → Require Variable Declaration so every new module starts with Option Explicit. Misspelled variable names then stop the code instead of quietly creating empty variables.

The world of VBA starts with the Visual Basic Editor, or VBE. It’s where you write, edit, and manage all your VBA code and macros.

If you’re serious about learning VBA, understanding the Visual Basic Editor is one of the most important things you can do. That’s why, in this lesson, we’re going to explore every major component of the VBE and learn how each one works. By the end of this guide, you’ll be comfortable navigating the editor and ready to start writing your own VBA code.

Let’s get started.

One quick note: throughout this guide, I’ll use terms like VBA Editor, VB Editor, and VBE interchangeably. They all refer to the same thing—the Visual Basic Editor. So, don’t let the different names confuse you.

What is the Visual Basic Editor?

Visual Basic Editor is an application (a separate one) in which you can write and save all the VBA codes. In simple words, it’s a code editor for Excel in which you can write all the macros and store them. Even though it is a separate application (VB Editor), you can only use it with Excel (or the other Office app it opens from).

Yes, that’s right. You can’t run VBE separately; Excel must be open for using VBE.

Visual Basic Editor is the only way to write a VBA code in Excel. In fact, all Microsoft applications that host VBA use the Visual Basic Editor for script writing (writing code).

Below is the VBE:

Microsoft Windows

vbe-window

Mac

visual-basic-editor-mac

VBA is one of the ADVANCED EXCEL SKILLS, and to master VBA, you need to learn all the aspects of Visual Basic Editor.

Excel Versions That Don’t Have a VBA Editor

There’s no workaround for these — VBA simply isn’t part of them:

  • Excel on the web (Excel in a browser) — no VBA editor, no macros
  • Excel for iPad, iPhone, and Android — you can open a macro-enabled file, but not the code
  • Excel Starter — the cut-down version pre-installed on some PCs

If you’re on one of these, the file will still keep its macros safely. Open it in Excel for Windows or Mac and the editor will be right there.

Alt + F11 on a Mac

On a Mac, the shortcut is Opt + F11. If that does nothing, hold Fn as well: Fn + Opt + F11. To stop having to press Fn every time, go to System Settings ➜ Keyboard and turn on the option to use F1, F2, and other keys as standard function keys.

Opening the editor by accident? If Alt + F11 keeps launching the editor when you meant to press something else, there’s no setting to switch it off — but pressing Alt + F11 again (or Alt + Q) takes you straight back to your worksheet. Alt + Q closes the editor window, but your code stays in the workbook.

Open the Visual Basic Editor

From the developer tab

To open the visual basic editor from the ribbon, you need to have the developer tab on the ribbon, and to activate the developer tab, follow these (steps to add).

developer-tab

Now on the developer tab, in the code group, there is a button called “Visual Basic” and when you click on this button it opens the VB editor.

visual-basic-button

Shortcut Key (Windows)

You can also use the keyboard shortcut key Alt + F11 to open the VBE in Windows and Opt + F11 or Fn + Opt + F11 on a Mac.

Even if you don’t have the developer tab on the ribbon, this shortcut key will still work and open the editor.

Edit a Macro from the List

If you want to open the VBA editor to edit a specific macro, then you can open the macros list from the developer tab.

edit-a-macro-from-the-list

And click on the edit button to open the VB editor to edit that specific macro.

edit-button-to-open-the-vb-editor

On Quick Access Toolbar

You can also add a button on the quick access toolbar to open the VBA editor. For this, you need to click on the drop-down on the quick access toolbar and open more commands.

quick-access-toolbar

And then select the developer tab from “Choose Commands From” and then add the visual basic editor to the quick access toolbar by clicking on the add button.

developer-tab-from-choose-commands

Now you can open the visual basic editor from the button that you have on the QAT.

quick-access-toolbar

From the Worksheet Tab

You can also open the VBA editor by right-clicking on the worksheet tab and clicking on View Code. It will instantly take you to the code window of that worksheet.

worksheet-tab

Components of Visual Basic Editor

When you open the VBA editor for the first time, it looks like an old application, and to understand how it works, you need to go component by component.

components-visual-basic-editor

The user interface has been (almost) the same in all the Excel versions for more than 15 years, so no matter which Excel version you are using, you can learn about Visual Basic Editor from this guide. Yes, VBE has different components which can help you in different ways, so let’s explore them one by one.

  1. Menu Bar
  2. Tool Bar
  3. Project Window
  4. Properties Window
  5. Code Window
  6. Immediate Window
  7. Watch Window
  8. Object Browser
  9. Find and Replace
  10. Locals Window

1. Menu Bar

Just like any other application, the VBA editor has a menu bar where you can find all the options that are available to the user.

vba-editor-menu

Now in the menu bar, each tab is a category of options that are available to use. For example, in the Edit menu, you can see all the options from cut-copy-paste and find and replace to indent and outdent.

menu-bar-tab-options

Along with all the options (most of them), you can find the shortcut keys to use those options.

2. Tool Bar

Just below the menu bar, you have the toolbar, which is a collection of some of the options that a normal user needs to use more frequently. When you open the visual basic editor for the first time, you will only have the Standard toolbar, just like the image below.

tool-bar

But there are a total of four toolbars that you can add and use.

  1. Debug
  2. Edit
  3. Standard
  4. User Form

If you go to the view tab in the menu bar you have the option to add or remove these toolbars.

tool-bar-tab-options

And you can also add or remove buttons from the toolbar if you want.

add-or-remove-buttons-from-the-toolbar

You can also move a toolbar just by dragging and dropping from the small dots on the right side.

drag-and-drop-from-the-small-dots

3. Project Window/ Project Explorer

The project window is the place where you can see all the ongoing projects. Whenever you open a file and then open the visual basic editor, you can see the hierarchy of that file in the project window.

project-window

Every project further has a collection of objects:

  • Worksheet: Each worksheet in a workbook lists as an object.
  • The Workbook: It represents the workbook itself as an object.
  • Module: It’s the place where you write code and where recorded macros are stored.
  • Chart Sheet: The chart sheet in the workbook will also be listed there.
collection-of-objects

When you open the VB editor, you’ll find the project window there by default. But if it’s not there somehow, you can add it from the View menu, or you can use the shortcut key Control + R.

Each object that is listed on the project window has its own code window which you can open by double-clicking on it, or you can right-click and select the View Code option.

select-view-code

The project window is the best way to navigate through all the ongoing projects and when you start working with the editor you will get to know more about it.

4. Properties Window

As the name suggests, the properties window gives you access to the properties of the selected object. Each object, for example, a worksheet has its own properties that you can see and change.

properties-window

For each property, there is a drop-down on the right side from where you can change or edit that property.

property-drop-down

Quick Tip: You can change the name of a project from the properties window.

change-the-name-of-a-project

And, if the properties window is not there by default, you can activate it from the View menu, or you can also use the shortcut key F4.

shortcut-key-f4

5. Code Window

The code window is the place where you write codes and do most of your work (editing, writing, and testing). In simple words, the code window is the place where you do all the programming.

code-window

When you first see it, it looks like a simple text editor, but it has Intellisense that can help you while programming.

There is no way I have found to add line numbers in the code window as other code editors have, but still, the VB editor shows the line (Ln) and column (Col) of the cursor on the Standard toolbar.

Note
There’s no way I have found to add line number in the code window as other code editors have but still, the VB editor indicates you the line number of the code.

6. Immediate Window

The Immediate Window is the place where you can debug your code. You can type a line of code and test how it works. Let’s say you want to test the following code:

Range("A1").Value = 9999

All you need to do is paste the code there and HIT Enter. It runs immediately, and cell A1 gets 9999. And if you want to see a value instead, type a question mark before it, like ?Range(“A1”).Value, and the result shows in the next line.

immediate-window

The other way is to add Debug.Print before an expression in your macro and get its result in the immediate window. The code below prints True if cell A1 has “Yes” and False if it doesn’t.

Sub Macro1()
Debug.Print Range("A1").Value = "Yes"
End Sub
add-debug-print

By default, the immediate window won’t be there when you open the visual basic editor, so you need to activate it from the View menu. You can also use the shortcut key Control + G.

7. Watch Window

Just like Excel Watch Window, the visual basic editor also has a watch window where you can add expressions to track them. You simply need to select the expression and then right-click and go to add a watch.

watch-window

In the below example, I have added the Selection.Value to the add watch.

52-added-the-selection.value_

Now, to activate the watch window, go to the View menu and click on the Watch Window option.

53-the-watch-window-option

And here you have the watch window tracking the added expression.

54-watch-window-tracking

8. Object Browser

VBA has its own object browser which can help you to work with all the objects by finding all the properties which you can use.

object-browser

Imagine you want to use the Range object; the object browser will tell you about all the properties and methods that come with it. Look at the below example.

range-object-browser

To open the object browser, use the shortcut key F2 or you can also go to the View menu and click on Object Browser to open it.

9. Find and Replace

Just like the find and replace in Excel, the VBA editor has its own find and replace option that you can use to find and replace values from procedures. To open the FIND option, you can use the shortcut key Control + F, and to open the replace you can use the shortcut key Control + H.

Otherwise, you can open both options from the edit menu.

find-and-replace

The find and replace option in VBE gives you different search patterns, like, if you want to find and replace something from the current procedure, from the current module, or from the current project.

You can also use the CASE SENSITIVE search and decide the direction of the search as well.

10. Locals Window

You can use the Locals window in VBE to display all declared variables in the current procedure and their present values while the code is paused (in break mode). Open it from View ➜ Locals Window.

Using VB Editor to Write a Code

At this point, you know all the major components of the VBA editor, so now let’s learn how to add code to it.

Module Code Window Vs Object Code Window

There are two different types of code windows, and both look just the same, but there is a difference that you need to know.

  1. Module Code Window: Code in the normal module can be executed manually or you can also call it from a separate procedure.
  2. Object Code Window: Code in the object code window can be executed by using an event. Let’s suppose you want to run code when you double-click on a cell. In that case, you need to use the BeforeDoubleClick event and you need to add code to that worksheet.

2. Module Code Window

You will be writing most of the VBA code in a module. To add code in a module you need to use the SUB procedure or the FUNCTION procedure.

  • Sub procedure
  • Function procedure

The difference between a sub and a function procedure is that a sub procedure can’t return a value, while a function procedure can return a value.

When you record a macro, that code goes straight into a module that VBA inserts automatically when you use the macro recorder.

Insert a Module

When you need to write code, you have to insert a module and for this, you simply need to go to the project window, right-click on the project name, and from that menu, go to Insert and select Module.

insert-a-module

Remove a Module

You can also remove a module if you don’t need it anymore. You simply need to right-click on the module and select Remove.

remove-a-module

And when you click on Remove, it asks you if you want to export (back up) that module before removing it. There is also an option where you can export a module to save it as a file in your system.

3. Object Code Window

To open the code window for an object, you simply need to double-click on it. In the code window, select the object from the left dropdown (like Worksheet), and then select the event that you want to use to execute the code from the right dropdown.

object-module

Imagine you want to write the code and execute it on a double-click; then you need to select “BeforeDoubleClick” from the dropdown.

Understanding Design Mode, Run Mode, and Debug Mode

You can use the visual basic editor in three different modes, depending on the phase of programming: writing the code, running it, and locating and fixing an error.

  • Design Mode: Normally, when you are working on a code in the VB editor, you are in design mode. Even when you are just writing code (not designing a user form), you are in design mode. This is also called design time.
  • Run Mode: When you run a code to test how it works, you are in run mode. The best example to define this mode is when you execute a code using the Run button from the toolbar. This is also called runtime.
  • Break Mode: When a code is running and the execution is paused in between, you are in break mode. In this mode, you can run a code step by step. This is also called debugging.

Tips to work with VB editor like a PRO

Adding Comments to a Code

Just like in any other programming language, in VBA, you can also use comments to describe how the code works. Using comments is a good habit and it can help you in so many ways.

  • Track Changes
  • Contact Details of the Programmer
  • How to Troubleshoot the Code
  • And much more

To add a comment, you need to type an apostrophe and then the comment text.

Related Tip: VBA Comment Block

Quick Info

Now, look at the below example, where I am adding a VBA function (VBA LEFT Function), and the moment I type the name of the function, it shows me a tooltip for all the arguments which I need to define.

31-quick-info

You can also use the shortcut key Control + I or use the quick info option from the EDIT menu.

32-shortcut-key-control-i

Auto List Members

Each object in VBA comes with some properties and methods, and when you insert an object or a command in the code window and then enter (.), it shows you the complete list of properties and methods which come with that object.

auto-list-members

In the above example, when I added a (.) after the borders property of the range, it showed me all the properties that are available to access.

List Constants

While defining expressions for a property or a method, you can use the list of constants (Using Constants in VBA) available. In the below example, while using the BorderAround method, it showed me all the constants which are available for the weight argument.

list-constants

You can use the shortcut key Control + Shift + J to get the list of constants or you can also go to the edit menu and use the option from there.

shortcut-key-control-shift-j

Activate Option Explicit

While writing VBA codes, you will need to use variables, and one of the most important things while using variables is to declare them. And there’s a chance that you could forget to declare one.

But when you use the option explicit statement, then you have to declare every single variable which you are using (with Dim), and if you fail to do so, VBA will show the “Variable not defined” error. It’s like forcing yourself to declare every single variable. To add it to every new module automatically, go to the Tools menu and open Options.

activate-option-explicit

And from the options, tick mark “Require Variable Declaration” and click OK.

require-variable-declaration

Now every new module will have an Option Explicit statement at the beginning, and you have to declare every single variable. For modules you already have, type Option Explicit at the top yourself.

option-explicit

Change the Code Window View

You can write multiple codes in a single code window, and VBA separates them with a divider, but if you want to have a more focused view, you can change the view of the code window. Below I have the codes in a single module.

change-the-code-window-view

But I can change this view from the view buttons from the bottom left of the window.

Now I have only the active code visible.

Run a Code Step by Step

When you write a VBA code, there could be a chance that the code has a bug or an error that can come while executing it. In that case, the best way is to execute that code step by step and validate each line of code.

run-a-code-step-by-step

For this, you can use the shortcut key F8 to execute a code line by line or use the Step Into option from the Debug menu.

shortcut-key-f8-to-execute-a-code-line43-shortcut-key-f8-to-execute-a-code-line

And there is also a button on the debug toolbar that you can use.

button-on-the-debug-toolbar

Code Indenting

When you write lengthy and complex codes, it’s important to structure them in the right way so that you can understand them later. For this, there’s one thing that comes in handy: INDENTING. Indenting is basically structuring the code using tabs, below is an example.

code-indenting

To add indenting in a line you can use the TAB key from the keyboard, or you can also use the indent/outdent buttons from the toolbar.

indentoutdent-buttons

Get Code from a Text File

The visual basic editor allows you to import VBA codes from a text file without copy-pasting. Once you insert a module, you can go to the Insert menu and select the File option from there.

get-code-from-a-text-file

It opens the dialog box where you can locate the text file and import all the codes from it to the current module.

R1C1 Reference Style

If you have ever worked with the R1C1 reference style, then I’m sure you can agree that it’s way easier to write formulas in codes with it (using the FormulaR1C1 property).

R1C1 Reference Style

Line Break

Even though you can adjust the width of the code window and make it wide, there could be situations where you are dealing with long lines of code that are hard to read.

The best way to deal with this problem is to add a line break. Basically, a line break is when you break a line into two lines using the line continuation character.

Use a SPACE & UNDERSCORE and hit enter to add a line break.

line-break

Formatting

When it comes to the user interface, the visual basic editor is not that good-looking. But there are a few formatting options that you can use to customize it or change its look the way you want.

From Tools ➜ Options ➜ Editor Format, you can access the formatting options, where you can change the font, the font size, and the text and background colors as well.

50-formatting-option

Check out this video on customizing the VBA editor for a dark theme.

Personal Macro Workbook

There could be some macros that you need to access within all the workbooks that you use.

In that case, you can use the Personal Macro Workbook which can help you to store all the important codes in one place and you can access them from all the workbooks.

55-personal-macro-workbook

Using Bookmarks

The visual basic editor allows you to add bookmarks to a line from Right Click ➤ Toggle ➤ Bookmark.

56-using-bookmarks

And then you can also navigate between bookmarks from the option in the edit menu.

57-navigate-between-bookmarks

Syntax Checking

When you write codes in the code window, VBA checks for syntax errors and notifies you when you make one. This option is activated by default, but you can also turn it off if you don’t want VBA to notify you every time you make an error.

Tools Menu ➤ Options ➤ Editor Tab ➤ Auto Syntax Check.

58-syntax-checking

But I would recommend you not to deactivate it because it can help you to identify all the syntax errors that you make while writing codes. Even with this option off, a line with a syntax error still turns red.

To check all the code in the project at once, use Debug ➜ Compile VBAProject. It goes through every module and stops at the first line with an error, like an undeclared variable when you use Option Explicit.

List of Macros

If you have a lot of macros in a module, there is an option that you can use to see all the macros (Tools ➤ Macro).

59-list-of-macros

There’s one big benefit of using this list option: you can run a macro, delete it, and edit it without navigating to that procedure.

Locking a Project with a Password

Visual Basic Editor also gives you the option to lock the project (all the modules in the workbook) with a password. So, if you don’t want the users to see the code or make changes to it, you can use this option. Tick “Lock project for viewing”, enter the password, and then save, close and reopen the workbook for the lock to work.

locking-a-project-with-a-password

Tools Menu ➤ VBAProject Properties ➤ Protection Tab

vbaproject-properties

Important Shortcut Keys

  • F2: Object browser.
  • F5: Run macro.
  • Tab: Add an indent.
  • Alt + Q: Close.
  • F8: Step into.
  • Control + H: Find and replace.
  • Control + G: Immediate Window.
  • Control + R: Project Explorer.
  • F4: Properties window.

Learn some AMAZING Keyboard Shortcuts: Excel Keyboard Shortcuts Cheat Sheet

Alternative to Visual Basic Editor

Well, I have tried quite a few other editors to write a macro, but the problem which I have found is that without the IntelliSense, it’s really hard to use anything other than the visual basic editor itself.

alternative-to-visual-basic-editor

The VBA editor works along with Excel: you can test your codes instantly, and you can save them in the workbook. Code written in another editor still needs to be pasted or imported into the VBE to run. But here are a few names to try.

Visual Studio Code | Ultra Edit

Points to Remember

  • You can maximize or minimize the code window.
  • You can change a project’s name anytime.
  • The project window is the best way to navigate through the editor.
  • It will make a line red if there’s a syntax error in it while writing the code.
  • You can also add a bookmark to a line of code from the Right-Click Menu Toggle Bookmark.
  • You cannot use the visual basic editor without opening Excel.

Frequently Asked Questions

How do I get back a missing window in the VBA editor?

Use the View menu or the shortcuts: Control + R for the Project Explorer, F4 for the Properties window, F7 for the code window, and Control + G for the Immediate Window. If a window opens in an odd place, drag it by its title bar back to the edge to dock it.

How do I make the code font bigger?

Go to Tools ➜ Options ➜ Editor Format and change the Size. There’s no zoom in the code window, so this is the way to make the code easier to read.

How do I move code to another workbook?

Drag the module from one project to another in the Project Explorer, or right-click the module, select Export File to save it as a .bas file, and then use File ➜ Import File in the other workbook.

Puneet Gogia

Written by

Puneet Gogia

Microsoft MVP — Excel · Founder, Excel Champs

Twelve years of teaching Excel, and a decade before that using it as a data analyst. Every tutorial here is written from a file I actually built.

3M+ readers helped
1,000+ tutorials written
Since 2015 teaching Excel