Article ID: 184188
Article Last Modified on 6/17/2005
Sub AutoTextEntryExample()
Dim sATName As String
Dim sATEntry As String
Dim sATNewEntry As AutoTextEntry
' Sample AutoText entry name.
sATName = "ExampleAutoTextEntryName"
' Sample AutoText entry text of 500 characters.
sATEntry = String(500, "A")
If Documents.Count = 0 Then Documents.Add
If Len(sATEntry) < 256 Then
' If the length of the text is less than 256 characters,
' add it as a new AutoText entry.
Selection.Range.Collapse
Set sATNewEntry = NormalTemplate.AutoTextEntries.Add _
(Name:=sATName, Range:=Selection.Range)
sATNewEntry.Value = sATEntry
Else
' If the length of the text is greater than 255 characters,
' insert it into the active document and add it as a new
' AutoText entry.
With Selection.Range
.Collapse
.Text = sATEntry
.Select
NormalTemplate.AutoTextEntries.Add _
Name:=sATName, Range:=Selection.Range
.Delete
End With
End If
End Sub
181058 OFF98: How to Run Sample Code from Knowledge Base Articles
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: wordcon vb vba vbe
Keywords: kbnofix kbmacroexample kbprb kbdtacode KB184188