Excel VBA: How to Open the Editor and Run Macros Safely

VBA & macros · Updated November 2, 2026

Excel VBA: How to Open the Editor and Run Macros Safely

In Excel for Microsoft 365 on Windows, press Alt+F11 to open the VBA editor, or choose Developer > Visual Basic. To open an existing VBA project, open its workbook in desktop Excel first, then use the same shortcut; if the Developer tab is missing, you can turn it on in Excel’s ribbon settings.

Open the VBA editor in Excel for Windows

The Visual Basic for Applications (VBA) editor is a separate window included with the desktop versions of Excel. It is where you can view, write, and organize VBA code. The quickest way to open it is Alt+F11. On some laptops, you may need to hold Fn as well, depending on how the function keys are configured.

You can also open it with the ribbon:

  1. Open the workbook in the Excel desktop app.
  2. Select Developer on the ribbon.
  3. Choose Visual Basic.

The editor can appear in front of Excel or behind it. If it seems that nothing happened, check the taskbar or switch between open windows. To return to Excel, select its window or press Alt+F11 again. Opening the editor does not, by itself, run any code or change the workbook.

Show the Developer tab if it is missing

The Developer tab is hidden by default in many Excel installations, but you do not need it to open the editor if Alt+F11 works. To show the tab on Windows, select File > Options > Customize Ribbon. In the list of main tabs on the right, select the Developer checkbox and choose OK. Developer then appears on the ribbon, where it provides access to Visual Basic, macros, and other development tools.

Ribbon names or window layouts can vary slightly with updates and display size. If the Options window is difficult to find, use Alt+F11 instead; the editor shortcut is often the simplest route. The Developer tab is a display setting for Excel, not a permission to run every macro on your computer.

Find a workbook’s VBA project and code

When the editor opens, look for the Project Explorer panel, usually on the left. If it is not visible, press Ctrl+R in the editor or choose View > Project Explorer. Each open workbook generally has a project listed as VBAProject, followed by the workbook name. Expand the project to see its objects and code containers.

Common items in a project include:

  • Microsoft Excel Objects: worksheet objects and ThisWorkbook. Code placed on a worksheet can respond to events on that sheet; ThisWorkbook can contain events related to the workbook itself.
  • Modules: standard code containers that commonly hold macros you can run directly.
  • Forms or class modules: components used for custom interfaces or more structured VBA projects.

Double-click an object or module to view its code. If you are looking for a particular routine, use Ctrl+F in the editor to search. A workbook can contain several modules, and an empty module does not mean the entire project is empty. If Project Explorer is open but you do not see the expected project, confirm that the correct workbook is open in Excel.

Create and run a simple macro

To add a basic macro, select the workbook’s project in Project Explorer, then choose Insert > Module in the editor. Paste or type a procedure into the new module. This example displays a message and does not edit worksheet data:

Sub ShowMessage()
    Dim messageText As String
    ' Set the text to display in the message box.
    messageText = "The VBA editor is open."
    MsgBox messageText, vbInformation, "VBA is ready"
End Sub

Before running any macro that could change data, save a separate copy of the workbook. VBA changes cannot be undone with Ctrl+Z, and a macro may alter or delete information. To run the example, click inside the procedure and press F5, or return to Excel and choose Developer > Macros, select ShowMessage, then choose Run. On Windows, Alt+F8 opens the Macro dialog. On a Mac, Option+F8 commonly opens it; the Fn key may also be needed on some keyboards.

A macro that appears in the Macro dialog generally needs to be a public procedure in a standard module and have no required arguments. Event procedures, such as code that runs when a worksheet changes, work differently: they run in response to the relevant event rather than appearing as an ordinary macro to launch from the dialog.

Open another workbook using VBA

Sometimes “open VBA” means using a VBA procedure to open an Excel file. The following example opens a specified workbook as read-only and avoids updating external links automatically. Replace the example path with the full path to a file you trust. Confirm that the workbook is saved elsewhere before running any macro that might change it.

Sub OpenWorkbookExample()
    Dim filePath As String
    Dim sourceBook As Workbook

    ' Replace this example with the workbook's actual path.
    filePath = "C:\Reports\Sales.xlsx"

    ' Stop with a message if the file is not at that location.
    If Len(Dir(filePath)) = 0 Then
        MsgBox "File not found: " & filePath, vbExclamation
        Exit Sub
    End If

    ' Open without writing changes to the source workbook.
    Set sourceBook = Workbooks.Open(Filename:=filePath, UpdateLinks:=0, ReadOnly:=True)
End Sub

The path must match the location and file name, including the extension. A path on another computer or a network drive may require different permissions or a reachable connection. ReadOnly:=True helps prevent saving changes back to that file, but it is not a substitute for a backup. If the file is already open, Excel may activate the existing workbook instead of creating another copy. Opening a file with VBA does not mean its macros are automatically safe to enable.

Save VBA code in the right file format

If a workbook contains VBA, save it in a format that preserves macros. In Excel, use File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm) for a standard macro-enabled workbook. The older Excel Binary Workbook (*.xlsb) format can also store VBA. A regular .xlsx file does not preserve VBA code; Excel warns that features may be lost if you try to save a macro-enabled workbook in that format.

Code you want to keep should be saved with the workbook or exported and backed up separately. In the VBA editor, a standard module can be exported as a .bas file, which can later be imported into another project. Exporting a module is not the same as saving the workbook: worksheet data, references between code and workbook objects, and other project components may not be included in that single file.

Security: enable only macros you trust

Macros can automate useful work, but VBA can also make broad changes to files and data. Do not enable macros just because a workbook displays a prompt asking you to do so. Consider who sent the file, whether you expected it, and whether its purpose makes sense. If the source is uncertain, ask the sender or use a trusted, approved copy rather than changing Excel’s protections to make it run.

On Windows, macro controls are available under File > Options > Trust Center > Trust Center Settings > Macro Settings. The wording and available choices depend on your Excel setup and organization policies. Avoid enabling all macros globally. A safer approach is to leave the standard protections in place and follow your organization’s process for files or locations that have been verified as trusted. Work or school devices may be managed by an administrator, so some settings may be unavailable.

Files downloaded from the internet can receive additional protections in Windows, and Excel may block their macros. Do not try to bypass a block unless you have verified the file and understand why it needs to run. Opening the editor to inspect code can help a knowledgeable reader understand a project, but unfamiliar code is not automatically safe just because it is visible.

Windows, Mac, and Excel for the web

The steps above are for desktop Excel on Windows. In Excel for Mac, try Option+F11 to open the Visual Basic Editor; depending on the keyboard, you may also need Fn. You can also look for Visual Basic on the Developer tab or use Tools > Macro > Visual Basic Editor. To display Developer on a Mac, open Excel’s ribbon and toolbar customization settings and enable the Developer tab; labels can differ slightly by release.

Excel for the web does not let you create, edit, or run VBA macros. You can store a macro-enabled workbook in a cloud location and open it in the browser for supported spreadsheet tasks, but you must open it in a compatible desktop Excel app to use its VBA project. If the editor shortcut does not work in a browser, switch to the desktop app rather than repeatedly trying the shortcut.

Common problems when opening VBA

  • Alt+F11 does nothing: Check whether the Fn key is required, make sure Excel is the active app, and try Developer > Visual Basic. A browser tab or another application may be receiving the shortcut instead.
  • The project is not listed: Return to Excel and check that the workbook is open. In the editor, show Project Explorer with Ctrl+R and expand the relevant project.
  • You can see code but cannot run it: The procedure may be an event routine, may require arguments, or may be in a location that does not appear in the Macro dialog. Check the code’s procedure type and module.
  • Excel blocks the macro: Treat the warning as a security decision, not a routine obstacle. Verify the source and follow your organization’s policy rather than turning off protections broadly.
  • The code disappears after saving: Check that you saved as .xlsm or .xlsb, not .xlsx, and confirm the save completed in the intended workbook.

Frequently Asked Questions

How do I open VBA in Excel?
On Windows, press Alt+F11 or choose Developer > Visual Basic. If the Developer tab is not visible, enable it through File > Options > Customize Ribbon.

How do I open a VBA file or project?
Open the workbook that contains the project in desktop Excel, then open the editor with Alt+F11 on Windows or Option+F11 on Mac. VBA code is usually stored inside an Excel workbook such as an .xlsm file, rather than opened as a standalone document.

Why does Alt+F11 not work?
Excel may not be the active window, or your keyboard may require Fn with the function key. You can also open the editor from Developer > Visual Basic. The shortcut does not work as a way to open the VBA editor in Excel for the web.

How do I open an Excel workbook with VBA?
Use the Workbooks.Open method in a VBA procedure, supplying the file path. Check that the file exists, consider opening it read-only, and use only files you trust. Save a backup before running code that could change workbook contents.

Can I run VBA macros in Excel for the web?
No. Excel for the web can work with many workbook features, but it cannot create, edit, or run VBA macros. Open the file in desktop Excel to use its VBA project.

Do I need to enable macros to open the editor?
No. You can open the editor and inspect a project without enabling its macros. Enable or run code only when you trust its source and understand the risks.

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.