Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 37 ยท Getting Started

What Is VBA?

Learn what VBA is, which Office apps run it, what it is good for, and when to choose it over formulas, Power Query, Office Scripts or Python.

VBA stands for Visual Basic for Applications. It is a programming language built into Microsoft Office (Excel, Word, Outlook, PowerPoint, Access and more). With it you can automate boring work, add your own buttons and dialogs, and make Office programs do things that menus and formulas cannot.

VBA is a "host" language: it lives inside an application and talks to that application's object model. In Excel it controls workbooks, worksheets and cells. In Word it controls documents and paragraphs. The language itself (variables, loops, procedures) stays the same everywhere, only the objects change.

VBA cannot run on this website. Every VBA snippet in this course is a read-only code block, and the output shown is only what the code really produces. Where an idea can be demonstrated in a browser, we add a clearly labelled JavaScript stand-in you can run and edit.

What can VBA do?

Typical jobs people hand to VBA:

  • Repeat work: format 40 sheets the same way, or clean a messy export in one click.
  • Combine files: pull data from many workbooks into one report.
  • Build tools: input forms, custom functions you can use in cells, validation rules.
  • Talk to other programs: create Word letters from Excel rows, send Outlook emails, read Access tables.
  • React to events: run code when a cell changes, a workbook opens or a file is saved.

One language, many apps

Excel Cells, sheets, charts.
Word Documents, ranges, tables.
Outlook Mail, calendar, tasks.
Access Tables, forms, reports.
1 / 2

A first look at VBA code

Here is a complete VBA procedure. It reads a name from cell A1 and shows a greeting.

VB
Sub Greet()
    Dim userName As String
    userName = Range("A1").Value
    MsgBox "Hello, " & userName & "!"
End Sub

Sub ... End Sub wraps a procedure. Dim declares a variable. Range("A1") is an Excel object, .Value is one of its properties, and MsgBox shows a dialog. VBA reads almost like English, which is why it is a popular first language for office workers.

How VBA is stored

VBA code is saved inside the document, not as a separate file. In Excel you must save the workbook as a macro-enabled workbook (.xlsm; Word uses .docm). A plain .xlsx file cannot hold macros and Excel will drop the code when saving.

Code lives in modules, which you edit in the Visual Basic Editor (the topic of the next lesson). A procedure that is called a macro is simply a Sub that takes no arguments and can be run from the Macros dialog or a button.

Stand-in: the same idea in JavaScript

You cannot run VBA here, but the mental model is the same in any language. The stand-in below is JavaScript, not VBA. It mimics an "Excel sheet" as an object, so you can see what Range("A1").Value means: look up an object, read a property.

JS Stand-in: a tiny object model

Press Run (or Ctrl + Enter) to see the console output here.

No output.

VBA versus other tools

Need Best tool
A calculation in a cell A worksheet formula
Cleaning and reshaping imported data Power Query
Cross-platform or cloud automation Office Scripts / Power Automate
Heavy analysis, machine learning Python
Desktop Office automation, custom dialogs, events, other Office apps VBA

VBA is old but still everywhere: millions of workbooks depend on it, it ships with Office with nothing to install, and it can control the whole desktop application. Its limits are that it runs only on Windows and (with differences) Mac desktop Office, not in the web versions, and macros are a security risk when they come from strangers.

Common mistakes for beginners

  • Saving as .xlsx and losing the code.
  • Opening files from email and enabling macros without checking the sender.
  • Trying to learn every object at once. Learn the language first, then one object model at a time.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does VBA stand for?

    VBA is Visual Basic for Applications, the language built into Microsoft Office.
  2. 2. Which file type can store VBA code in Excel?

    Only macro-enabled formats such as .xlsm (or the older .xls) keep VBA code.
  3. 3. What is an object model?

    The object model describes workbooks, sheets, cells and so on, so VBA can read and change them.
  4. 4. Which task is the weakest fit for VBA?

    Excel for the web does not run VBA; use Office Scripts there.

Summary

  • VBA is the programming language built into Microsoft Office.
  • It controls an application through its object model.
  • Code is stored in the document, so use macro-enabled file types.
  • Choose VBA for desktop Office automation; use formulas, Power Query or Python where they fit better.

Next: The VBA Editor and Macro Security