VBA steht für „Visual Basic for Applications“ und ist eine Programmiersprache, die in Microsoft Office-Anwendungen integriert ist. Mit VBA kann man automatisierte Abläufe, Makros und benutzerdefinierte Funktionen erstellen.
Den VBA Editor öffnet man mit ALT + F11
Ein Sub (Unterprozedur) ist eine Ansammlung von Anweisungen, wie eine Funktion.
Sub Greeting() MsgBox "Hello, World!" End Sub
Kommentare mit ' oder REM
' Dies ist ein Kommentar REM Ein weiterer Kommentar
Arbeitsmappen und Dokumente
Dim wb As Workbook ' für Excel Set wb = ThisWorkbook Dim doc As Document ' für Word Set doc = ActiveDocument
Dim rng As Range Set rng = Range("A1:B5") ' Bereich A1 bis B5 Dim cell As Range Set cell = Cells(1, 1) ' Zelle A1 Dim rng As Range Set rng = doc.Content MsgBox rng