Finding Out Which Property or Method to Use

Microsoft Word Visual Basic

Finding Out Which Property or Method to Use

   

You can use the macro recorder to find out what methods or properties you need to accomplish a task in Microsoft Word. The macro recorder is a tool that translates your actions into Visual Basic instructions. For example, if you turn on the macro recorder and open a document named Examples.doc, the macro recorder records an instruction similar to the following.

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 9/22/2000 by JeffSmith
'
    Documents.Open FileName:="Examples.doc", ConfirmConversions:=False, _
        ReadOnly:=False, AddToRecentFiles:=False, _
        PasswordDocument:="", PasswordTemplate:="", _
        Revert:=False, WritePasswordDocument:="", _
        WritePasswordTemplate:="", Format:=wdOpenFormatAuto
End Sub

The Documents property returns the Documents collection and the Open method opens the specified file name. When you're first learning Visual Basic, using the macro recorder will help you learn which properties and methods you need to use to accomplish a task.

For more information, see the following:

Revising recorded Visual Basic macros