When you click Edit, you open the VBA Editor.
Using the VBA Editor you can edit recorded
Macros or write a Word Macro from scratch. To access the VBA Editor use the shortcut ALT + F11
or click Visual Basic from the Developer Ribbon.
Simple Word Macro Example
This is a simple example of a Word VBA Macro. It performs the following tasks:
• Opens a Word Document
• Writes to Document
• Closes and Saves the Word Document.
Sub WordMacroExample()
‘Open Doc & Assign to Variable
Dim oDoc As Document
Set oDoc = Documents.Open(“c:\Users\someone\NewDocument.docx”)
‘Write To Doc
Selection.TypeText “www.automateexcel.com”
Selection.TypeParagraph
‘Save and Close Doc
oDoc.Save
oDoc.Close
End Sub
Word Macro Basics
All VBA code must be stored within procedures like this. To create a procedure in VBA type “Sub
WordMacroExample” (Where “WordMacroExample” is your desired Macro name) and press
ENTER. VBA will automatically add the parenthesis and End Sub.
AutoMacro:
VBA Add-in with Hundreds of Ready-To-Use Code Examples, Learn More
Code Generators, and much more!