AutoCorrectEntries.AddRichText method (Word)

Creates a formatted AutoCorrect entry, preserving all text attributes of the specified range. Returns an AutoCorrectEntry object.

Syntax

expression. AddRichText( _Name_ , _Range_ )

expression Required. A variable that represents an 'AutoCorrectEntries' collection.

Parameters

Name Required/Optional Data type Description
Name Required String The text to replace automatically with Range.
Range Required Range The formatted text that Word will insert automatically whenever Name is typed.

Return value

AutoCorrectEntry

Remarks

The RichText property for entries added by using this method returns True. If AddRichText isn't used, inserted AutoCorrect entries conform to the current style.

Example

This example stores the selected text as a formatted AutoCorrect entry that will be inserted automatically whenever "NewText" is typed.

If Selection.Type = wdSelectionNormal Then 
 AutoCorrect.Entries.AddRichText "NewText", Selection.Range 
Else 
 MsgBox "You need to select some text." 
End If

This example stores the third word in the active document as a formatted AutoCorrect entry that will be inserted automatically whenever "NewText" is typed.

AutoCorrect.Entries.AddRichText "NewText", ActiveDocument.Words(3)

See also

AutoCorrectEntries Collection Object

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.