Visual Basic

How To Open Excel Visual Basic

To open Excel Visual Basic on Windows, open a workbook and press Alt + F11, or select Developer > Visual Basic on the ribbon. If Developer is missing, enable it through File > Options > Customize Ribbon. The Visual Basic Editor lets you view, write.

Which licences fit your PC setup?

Prices are an AUD snapshot, not a live quote. Confirm variant and total on the listing.

Open the Visual Basic Editor on Windows

Visual Basic for Applications, usually shortened to VBA, is the programming language used for Excel macros. The Visual Basic Editor is the separate editing environment where you work with that code. You access it from Excel; you do not need to install a separate programming application.

Use the keyboard shortcut

  1. Open the workbook you want to work with in the Excel desktop application.
  2. Hold Alt and press F11 to open the Visual Basic Editor.
  3. Press Alt + F11 again when you want to return to the worksheet.

This shortcut works without displaying the Developer tab. Microsoft lists it in its Excel keyboard shortcut reference. If your keyboard uses F11 for a hardware function, you may also need to hold Fn.

Enable Developer and use the ribbon

If you prefer a visible button, add the Developer tab. You only need to enable it once unless your ribbon settings change.

  1. Select File, then Options.
  2. Choose Customize Ribbon in the Excel Options window.
  3. Under Main Tabs, tick the Developer checkbox.
  4. Select OK to return to the workbook.
  5. Select Developer, then Visual Basic in the Code group.

These ribbon settings follow Microsoft's instructions for showing the Developer tab. The Mac route uses different menus, as described below.

Open Visual Basic in Excel for Mac

Excel for Mac also includes the Visual Basic Editor. To access it through the ribbon:

  1. Open a workbook in desktop Excel.
  2. From the Excel menu, select Preferences, then Ribbon & Toolbar.
  3. Under Customize the Ribbon, choose Main Tabs and tick Developer.
  4. Select Save and close Preferences.
  5. On the Developer tab, select Visual Basic.

Microsoft documents this setup in its guide to using the Developer tab in Excel for Mac.

Find your workbook and code

Opening the editor does not automatically create a blank module. A new workbook may have no code window open, so an empty editing area does not mean something has gone wrong.

Start with these parts of the editor:

  • Project Explorer lists open VBA projects and their contents. Find the project whose name includes your workbook's filename.
  • The Code window displays the code for a selected module, worksheet or workbook object.
  • The Properties window shows properties for the selected item, such as a module's name.
  • The Immediate window accepts individual commands and displays debugging output. It is useful later, but you do not need it simply to open or read a module.

If a pane is missing, use the editor's View menu to display it. On Windows, Ctrl + R displays Project Explorer and Ctrl + G opens the Immediate window. Microsoft's VBA View menu reference describes these controls.

For more detail on how the workspace fits together, read what the Visual Basic Editor in Excel does.

Open existing code or add a module

In Project Explorer, expand your workbook's project. If it contains a Modules folder, expand that folder and double-click a module to view its code. Worksheet and workbook event code belongs to the relevant objects under Microsoft Excel Objects.

For a new general-purpose macro, create a standard module:

  1. Select the intended workbook's project in Project Explorer.
  2. Choose Insert > Module from the editor's menu.
  3. Use the new module's Code window to write your macro.

Check the workbook name before adding code, especially when several workbooks are open. A standard module is a useful starting point for a macro you run manually; worksheet and workbook event procedures need their corresponding object modules.

Save the workbook with its VBA code

A standard .xlsx workbook cannot store VBA code. After adding a macro, use File > Save As in Excel and choose Excel Macro-Enabled Workbook (*.xlsm). Then save the file. Microsoft's guide to saving a macro explains the required format.

If Excel warns that VBA cannot be saved in the selected format, return to the file-type selection and choose .xlsm. Saving as .xlsx removes the code from that saved copy.

Check these points if the editor does not open

  • Using a browser: Excel for the web cannot create, run or edit VBA macros. Open the workbook in desktop Excel, as described in Microsoft's guidance on working with VBA files in the browser.
  • Shortcut does nothing: try Developer > Visual Basic to check whether the issue is the function-key combination.
  • Editor opens without code: select your workbook in Project Explorer, then open an existing module or insert a new one.

Once you can access the editor, choose a small task to practise, such as applying consistent formatting to a report. Our guide to where Visual Basic is useful can help you choose, while the Visual Basic articles provide further reading.

Open a blank practice workbook now, insert a standard module and save the workbook as .xlsm before adding your first macro.

Other editions for separate workloads

Other editions for separate workloads; prices in AUD, confirm the total on the listing.

How to check this worked

  1. Open Settings, System, Activation and confirm the edition shown.
  2. Enter the key and run activation; expect a green tick within a minute.
  3. Reboot and re-check activation survives the restart.

FAQ

What else should you know before buying?

What do I need before starting?
Read the requirements and confirm the edition first; the steps assume the machine is compatible.
How do I know the licence is genuine?
Activate on Microsoft's servers and check Settings, System, Activation. A working activation is the test.
Is this a subscription?
Keys sold here are one-time lifetime licences. Microsoft 365 plans are billed by Microsoft instead.
What if the key fails?
Email hi@ms.codes with the order number and a screenshot. Replacement or refund applies within 30 days.

Check who prepared and reviewed this guide

Written by
MS.Codes editorial
Reviewed by
Support team

Last verified: (source review; see test status above).

Recent Post