Microsoft Learn is Microsoft's free documentation and training site, and it hosts the official reference for Excel VBA (Visual Basic for Applications), the programming language built into Excel. It does not run VBA for you and it is not an editor: it is where you read the correct syntax, object model entries and sample code that you then paste into Excel's own Visual Basic Editor. To get the most from it, you need a desktop copy of Excel that supports macros, the Developer tab switched on, and a workflow for moving code between the documentation and your workbook. The steps below cover all of that.
What You'll Need
- A desktop version of Excel on Windows or Mac. VBA does not run in Excel for the web, and macro editing is not available there.
- An internet connection and a browser for reading Microsoft Learn documentation.
- The Developer tab enabled in Excel, so you can reach the Visual Basic Editor and macro settings.
- Macro security settings that allow you to run your own code. By default Excel blocks macros from untrusted locations, so you will save your practice workbook in a trusted folder.
- A blank workbook you are willing to experiment in. Do not trial code in a workbook you cannot afford to lose.
Step-by-Step
- Enable the Developer tab. In Excel on Windows, open File > Options > Customize Ribbon, tick Developer in the right-hand list of main tabs, and click OK. On Excel for Mac, open Excel > Settings (or Preferences, depending on version), go to Ribbon & Toolbar, and tick Developer. Menu wording shifts slightly between versions and platforms, so look for the ribbon customisation screen rather than a specific label.
- Set your macro security. Open the Developer tab and click Macro Security. Choose the option that disables macros with notification, so Excel asks before running anything. Avoid the setting that enables all macros — it removes the prompt that protects you from malicious files.
- Save a practice workbook as macro-enabled. Use File > Save As and pick the .xlsm format (Excel Macro-Enabled Workbook). Standard .xlsx files silently discard any VBA you add, which is one of the most common reasons code seems to vanish.
- Open Microsoft Learn and find the VBA reference. Go to learn.microsoft.com and search for "Excel VBA reference" or "VBA language reference". The Learn site mixes conceptual articles, language reference pages and object model entries. Bookmark the landing page you land on so you can return to it quickly.
- Read the object model before you write code. VBA in Excel works by addressing objects: Application, Workbook, Worksheet, Range and so on. On Learn, open the Excel object model reference and read the entries for Workbook, Worksheet and Range first. Understanding that a Range is a child of a Worksheet, which is a child of a Workbook, prevents most "object required" errors later.
- Copy a short sample into the editor. In Excel press Alt+F11 (Windows) or Option+F11 (Mac) to open the Visual Basic Editor. In the editor, use Insert > Module to add a blank module. Paste a small sample from Learn — something that writes a value into a cell — into the module window.
- Adapt the sample to your own sheet names. Samples on Learn use generic names. If yours reference a workbook called Book1 or a sheet called Sheet1, change them to match your actual file. Quote sheet names that contain spaces, for example Worksheets("My Data"), and remember names are case-insensitive but spelling must be exact.
- Run the code and watch what happens. Place the cursor inside the procedure and press F5, or use Run > Run Sub/UserForm. If Excel shows a macro dialog first, choose your procedure from the list. Watch the worksheet as it runs so you can see which cell changes.
- Use the Immediate window for quick checks. In the editor, press Ctrl+G (Windows) or Control+G (Mac) to open the Immediate window. Type a question mark followed by an expression, such as ? ActiveSheet.Name, and press Enter to print the result. This is the fastest way to confirm what an object actually refers to before you build on it.
- Step through code line by line when results are wrong. Press F8 to execute one line at a time. Hover over variables to see their current values, and use Debug > Toggle Breakpoint (F9) to pause at a chosen line. Learning this early turns guesswork into diagnosis.
- Look up each unfamiliar object on Learn as you meet it. When you encounter something like Offset, Resize or Find, search the Learn reference for that exact member. The reference pages list required and optional arguments, return types and remarks, which is more reliable than copying code from forums.
- Save your module and back it up. Keep the .xlsm workbook saved, and export important modules via File > Export File in the editor so you have a copy outside the workbook. Macros are lost if a file is corrupted, and exports are portable between workbooks.
- Practice with Learn's own examples. Learn's VBA articles include worked scenarios such as looping through rows or filling a range from an array. Retype them rather than pasting so you absorb the syntax, then change one thing at a time and re-run to see the effect.
Common Mistakes
Saving in the wrong format. A workbook saved as .xlsx will strip VBA on close. Always confirm the title bar shows the macro-enabled format before you trust your work.
Referenceing sheets by index. Code like Worksheets(1) depends on tab order and breaks when someone drags a sheet. Use the sheet's name or its code name instead.
Confusing Learn's reference with a tutorial. The reference documents syntax precisely but rarely explains a whole workflow. Pair reference pages with the conceptual articles rather than expecting the reference alone to teach the task.
Leaving Option Explicit off. Without it, misspelled variable names silently create new variables and produce wrong results. Add Option Explicit at the top of every module.
Forgetting that macros are disabled. If nothing happens when you press F5, check Macro Security and whether the workbook came from a downloaded location that Excel has flagged as untrusted.
Tips
Add a comment line above each procedure describing what it does and what sheet it expects. Future-you will not remember.
Use the editor's Object Browser (F2) to browse every member of an object without leaving Excel — it is the same information Learn publishes, available offline.
Keep scratch code in a separate module from production code so you can delete experiments without breaking working procedures.
Name your modules meaningfully and avoid renaming worksheet code modules, since those names are used by event procedures such as Worksheet_Change.
When adapting sample code, change one thing at a time and re-run. Stacking several edits makes it impossible to tell which one broke the result.
Troubleshooting
The Developer tab is missing. Return to the ribbon customisation screen and confirm Developer is ticked in the right-hand list. If a company policy manages your ribbon, the option may be greyed out — ask your administrator rather than editing the registry.
Nothing happens when you run the code. Confirm you are in a standard module, the cursor is inside the procedure, and the file is .xlsm. Check the Immediate window for any printed text, since a procedure may have run without visible output.
You get a compile error. Read the highlighted line, then check for a missing End Sub, an unclosed quote, or a name that does not exist in the object model. Learn's member pages show the exact spelling of every property and method.
A runtime error mentions an object or with block. Usually a referenced workbook or sheet is not open or is misspelled. Use ? ActiveWorkbook.Name and ? ActiveSheet.Name in the Immediate window to see what VBA is actually looking at.
Your code edits are not taking effect. Excel may still be running an older version in memory. Save, close the workbook, and reopen it, then run again.
Frequently Asked Questions
Is Microsoft Learn free to use?
Yes. Microsoft Learn's documentation and training modules are free to browse; only an internet connection is needed.
Does VBA work in Excel for the web?
No. Macros and the Visual Basic Editor require the desktop application on Windows or Mac.
Do I need to download anything from Learn?
No. Learn is a documentation site; you copy code into Excel's own editor. Some training paths include sample files you can download if you want them.
Is there an official VBA course on Learn?
Learn hosts modules and learning paths covering Office automation, but availability varies. Search the site for VBA and check what is currently listed rather than assuming a fixed curriculum.
Should I learn VBA or Office Scripts?
VBA runs in desktop Excel across Windows and Mac and is the right choice for legacy automation. Office Scripts is a separate, newer automation language tied to Excel on the web and Microsoft 365, and it does not support every desktop-only capability. Pick based on where your workbooks live and who maintains them.
Why does Excel warn me before running my own macro?
That is the macro security setting doing its job. Files downloaded from the internet are treated as untrusted; store your practice workbook in a folder you have marked as trusted rather than lowering the global setting.