VBA

Visual Basic for Applications — the automation and macro language for Microsoft Office products.

Object-Oriented
Event-Driven
Procedural
Beginner
1993
Microsoft

Overview

VBA (Visual Basic for Applications) is an implementation of Microsoft's Visual Basic built into Microsoft Office applications. It enables users to automate repetitive tasks, create custom functions, build forms, and extend Office functionality.

Key Features

  • Office integration — Direct access to Excel, Word, Outlook object models
  • Macro recording — Generate code by recording user actions
  • UserForms — Build custom dialog boxes and input forms
  • COM automation — Control other Windows applications
  • Immediate Window — REPL-like debugging and testing

Code Example

vb
Sub SummarizeData()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets("Sales")

    Dim lastRow As Long
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row

    With ws.Range("A1:D" & lastRow)
        .Borders.LineStyle = xlContinuous
        .Font.Name = "Calibri"
    End With

    ws.Cells(lastRow + 1, 1).Value = "Total"
    ws.Cells(lastRow + 1, 4).Formula = "=SUM(D2:D" & lastRow & ")"
End Sub

Learning Resources

Learning Path

10 topics across 3 sections

1Basics

2Excel Object Model

3Advanced

  • UserForms — Custom dialog boxes, controls, and event handling
  • Error Handling — On Error, Resume Next, and error logging
  • COM Automation — Controlling Outlook, Word, and external applications