How to See Visual Basic Code in Excel
Ever received an Excel file that does something magical? You click a button, and it instantly sorts data, generates a report, or highlights specific cells. That isn't magic, it's Visual Basic for Applications (VBA), the programming language built right into Excel that powers these automations. This guide will show you exactly how to pull back the curtain and see the VBA code running behind the scenes in any workbook.
What is Visual Basic for Applications (VBA)?
Think of VBA as Excel's secret superpower. It's a programming language that lets you tell Excel what to do, step-by-step. While you can build formulas and pivot tables using the standard interface, VBA allows you to automate repetitive tasks, create custom functions, build interactive forms, and manage complex processes with the click of a button.
Every time you record a macro in Excel, you're actually generating VBA code without writing a single line yourself. Learning to view this code is the first step toward understanding how to customize, troubleshoot, and eventually write your own powerful automations.
First, Reveal the Developer Tab
To access any of the VBA tools, you first need to enable the Developer tab, which is hidden by default in Excel. The process is slightly different for Windows and Mac, but it's quick and easy on both.
On Windows:
- Right-click anywhere on the Ribbon at the top of Excel (the area with Home, Insert, Page Layout, etc.) and select Customize the Ribbon....
- An "Excel Options" window will appear. On the right side, under the "Customize the Ribbon" list, you will see a list of Main Tabs.
- Find Developer in this list and check the box next to it.
- Click OK. You should now see the "Developer" tab appear in your Ribbon, usually after the "View" tab.
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
On Mac:
- Click Excel in the top menu bar (next to the Apple icon) and select Preferences... or Settings....
- In the window that opens, find the "Authoring" section and click on Ribbon & Toolbar.
- In the "Ribbon" tab, scroll down the list of "Main Tabs" on the right.
- Check the box next to Developer.
- Close the window. The "Developer" tab will now be visible in your top ribbon.
How to Open the Visual Basic Editor (VBE)
The Developer tab is your gateway, but the Visual Basic Editor (VBE) is where all the action happens. The VBE is a separate window from Excel where all the VBA code for a workbook is stored, written, and edited.
There are two primary ways to open it:
- The Button Method: Go to your newly enabled Developer tab and click the Visual Basic button on the far left.
- The Keyboard Shortcut: This is the method most professionals use because it's so fast. Press Alt + F11 on Windows or Option + F11 on Mac (on some Mac keyboards, you may need to press Fn + Option + F11).
Once you open the VBE, you'll see a new window with a few key panels. Don't be intimidated by the very "90s developer" look, you only need to focus on a couple of areas to start.
Understanding the VBE Interface
- The Project Explorer: Usually located on the top left, this panel is like a file tree for your Excel workbook. It shows all the sheets, user forms, and modules where code can live. If you don't see it, press Ctrl + R (Windows) or Command + R (Mac), or go to View > Project Explorer.
- The Code Window: This is the large, blank area on the right where the actual VBA code is displayed. When you select an item in the Project Explorer, its associated code will appear here.
- The Properties Window: Typically below the Project Explorer, this shows properties of the selected object (like a module or sheet). You can largely ignore this for now while you're just learning to view code. If it's getting in your way, you can hide it via View > Properties Window.
Where to Look for Code: Navigating the Project Explorer
So, you've opened the VBE. Now, where is the code hiding? VBA code can be stored in a few different places within your workbook, and the Project Explorer is your map.
In the Project Explorer, you’ll typically see a project named something like "VBAProject (YourWorkbookName.xlsm)". If you expand it, you will see a folder called "Microsoft Excel Objects" and potentially another folder called "Modules."
Code in 'Modules'
This is the most common place to find general-purpose code, especially code created by the Macro Recorder. A module is essentially a container for standalone VBA procedures (often called "macros" or "subroutines").
If there is a "Modules" folder in your Project Explorer, expand it to see all of the Module items contained inside (e.g., Module1, Module2, etc.). Just double-click on one of these items (e.g., Module1), and its contents — the VBA code — will appear in the code window.
Code in Worksheet or Workbook Objects
Sometimes, code is tied directly to a specific event on a worksheet or for the workbook itself. This is called "event-driven" code.
- Worksheet Code: Double-click on a sheet object in the "Microsoft Excel Objects" folder (e.g., Sheet1 (Sales Data)). This will open the code window for that specific sheet. This is where you would find code that runs automatically when you change a cell value, select a new cell, or right-click on that sheet only.
- Workbook Code: Double-click on the ThisWorkbook object. This contains code related to workbook-level events, such as code that runs automatically every time the workbook is opened (Workbook_Open) or just before it is saved (Workbook_BeforeSave).
Practical Example: Record and View Your First Macro
The best way to learn is by doing. Let's create some VBA code using the Macro Recorder and then find it in the VBE.
- Open a blank Excel sheet.
- Go to the Developer tab and click Record Macro.
- A small box will appear. You can give your macro a name — let's call it FormatHeader. Press OK.
- From now on, every action you take is being recorded. Let's perform some simple formatting:
- Now, go back to the Developer tab and click Stop Recording.
You've just created a macro! Now, let's find the code.
- Press Alt + F11 (or Option + F11 on Mac) to open the Visual Basic Editor.
- In the Project Explorer on the left, you will now see folders called "Modules." Expand this and you will find "Module1" (or whatever comes after it in the series). This was created automatically.
- Double-click on "Module1." You should instantly see the corresponding VBA code appear in the central code window.
The code will look something like this:
Sub FormatHeader()
'
' FormatHeader Macro
'
Range("A1").Select
Selection.Font.Bold = True
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent1
.TintAndShade = 0.799981688894314
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
End SubFree PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
Breaking Down the Code
Sub FormatHeader() ... End Sub: This defines the beginning and end of our macro named "FormatHeader".- Lines starting with an apostrophe are comments. They are notes for humans and are ignored by Excel when the macro runs.
Range("A1").Select: This line is pretty clear — it selects cell A1.Selection.Font.Bold = True: This takes the current selection and makes its font bold.- The sections starting with
With Selection...are just an efficient way to apply multiple properties (like color, pattern, etc.) to the same object (the selected cell).
By simply looking at the recorded code, you start to learn the syntax of VBA. You can see how easy it would be to tweak this macro. Want to format cell B1 instead? Just change Range("A1").Select to Range("B1").Select.
Why Bother Viewing VBA Code?
Seeing the code is more than just a curiosity. It’s a powerful tool for any serious Excel user.
- To Learn VBA: The Macro Recorder is your best tutor. Don't know how to write the code for creating a pivot table? Record yourself doing it and then study the code it produces.
- To Debug and Troubleshoot: If a macro you're using (or one inherited from a coworker) is not working correctly, viewing the code is the only way to find out what's wrong. You can step through it line-by-line to pinpoint the source of the error.
- To Customize and Enhance: Recorder-generated code is often clunky. Once you can read it, you can modify it to be more efficient or flexible. You could change hard-coded ranges like "A1" to apply to whatever cell the user has currently selected, making the macro more dynamic.
Final Thoughts
Pulling back the curtain on Excel's VBA code is simpler than you might think. By enabling the Developer tab and learning your way around the Visual Basic Editor, you've taken the first major step from being a casual user to an advanced one. It demystifies macros and empowers you to understand, adapt, and eventually create your own powerful automations directly within your spreadsheets.
But when your automation needs go beyond the spreadsheet, and you find yourself pulling reports from Google Analytics, Facebook Ads, Shopify, and Salesforce just to get data into Excel, another kind of automation is needed. That's why we built Graphed. We connect directly to all your key marketing and sales platforms, automating the entire data collection and reporting process. Instead of manually exporting CSVs and building dashboards, you can use simple English to ask questions and instantly get real-time charts and reports from all your connected sources in one place.
Related Articles
Facebook Ads for Pest Control: The Complete 2026 Strategy Guide
Learn how to run effective Facebook ads for pest control companies in 2026. This comprehensive guide covers campaign setup, targeting strategies, cost benchmarks, and best practices for generating quality leads.
Facebook Ads for Carpet Cleaners: The Complete 2026 Strategy Guide
Learn how to run Facebook ads for carpet cleaning businesses in 2026. Get proven strategies for targeting, creative formats, retargeting, and budget that actually convert.
Facebook Ads For Personal Trainers: The Complete 2026 Strategy Guide
Learn how to effectively use Facebook ads for personal trainers in 2026. This comprehensive guide covers targeting strategies, ad creative, budgeting, and optimization techniques to help you grow your training business.