

This is an example of accessing the “Selection” of “Windows(1)” with in the Application: Application.Windows(1). In addition to accessing other Word objects, there are “application-level” settings that can be applied: = True All other objects in Word can be reached through it. Selection Object – A selected range or cursor location.ĪutoMacro | Ultimate VBA Add-in | Click for Free Trial! ApplicationĪpplication is the “top-level” object. The most common objects are:Īpplication Object – Microsoft Word itself When interacting with Microsoft Word in VBA, you will frequently reference Word “Objects”. VBA will automatically add the parenthesis and End Sub. To create a procedure in VBA type “Sub WordMacroExample” (Where “WordMacroExample” is your desired Macro name) and press ENTER.

Selection.TypeText "Selection.TypeParagraphĪll VBA code must be stored within procedures like this. Set oDoc = Documents.Open("c:\Users\someone\NewDocument.docx") This is a simple example of a Word VBA Macro. To access the VBA Editor use the shortcut ALT + F11 or click Visual Basic from the Developer Ribbon.

Using the VBA Editor you can edit recorded Macros or write a Word Macro from scratch. When you click Edit, you open the VBA Editor. You can see a list of all available Macros from View > Macros.Īfter recording a Macro, you will be able to edit the Macro from the Macro List: When you Record a Macro, Word will write VBA code into a Macro, allowing you to repeat your actions. Macros are blocks of VBA code that perform specific tasks. VBA is the programming language used to automate Microsoft Office programs including Word, Excel, Outlook, PowerPoint, and Access. Note: If you’re brand new to Macros / VBA you might also find this article useful: How to write VBA Macros from Scratch. This tutorial will teach you how to write a simple Macro and interact with Documents, Ranges, Selections, and Paragraphs. This is a tutorial for using VBA with Microsoft Word. IParCount = Fori = 1 To iParCountĪctiveDocument.Paragraphs(i).Alignment = wdAlignParagraphLeft
