AutoTextEntries Collection Object

See Also         Properties         Methods        

Application object
Templates collection (Template object)
AutoTextEntries collection (AutoTextEntry object)

A collection of AutoTextEntry objects that represent the AutoText entries in a template. The AutoTextEntries collection includes all the entries listed on the AutoText tab in the AutoCorrect dialog box (Tools menu).

Using the AutoTextEntries Object

Use the AutoTextEntries property to return the AutoTextEntries collection. The following example determines whether an AutoTextEntry object named "test" is in the AutoTextEntries collection.

For Each i In NormalTemplate.AutoTextEntries
    If LCase(i.Name) = "test" Then MsgBox "AutoText entry exists"
Next i

Use the Add method to add an AutoText entry to the AutoTextEntries collection. The following example adds an AutoText entry named "Blue" based on the text of the selection.

NormalTemplate.AutoTextEntries.Add Name:="Blue", _
    Range:=Selection.Range

Use AutoTextEntries(index), where index is the AutoText entry name or index number, to return a single AutoTextEntry object. You must exactly match the spelling (but not necessarily the capitalization) of the name, as it's shown on the AutoText tab in the AutoCorrect dialog box. The following example sets the value of an existing AutoText entry named "cName."

NormalTemplate.AutoTextEntries("cName").Value = _
    "The Johnson Company"

The following example displays the name and value of the first AutoText entry in the template attached to the active document.

Set myTemplate = ActiveDocument.AttachedTemplate
MsgBox "Name = " & myTemplate.AutoTextEntries(1).Name & vbCr _
    & "Value " & myTemplate.AutoTextEntries(1).Value