Name Property

Microsoft Word Visual Basic

Name Property

       

Returns or sets the name of the specified object. 

Read/write String for the following objects: AutoCorrectEntry, AutoTextEntry, ColorFormat, CustomLabel, EmailSignatureEntry, Font, FormField, ListEntry, ListTemplate, Shape, ShapeRange, and TableOfAuthoritiesCategory; read-only String for all other objects in the Applies To list.

expression.Name

expression   Required. An expression that returns one of the objects in the Applies To list.

Example

This example adds a document variable to the active document and then displays the name of the first document variable.

ActiveDocument.Variables.Add Name:="Temp", Value:="1"
MsgBox ActiveDocument.Variables(1).Name

This example returns the name of the first bookmark in Hello.doc.

abook = Documents("Hello.doc").Bookmarks(1).Name

This example displays the names of the form fields in the active document.

If ActiveDocument.FormFields.Count >= 1 Then
    For Each FF In ActiveDocument.FormFields
        FFNames = FFNames & FF.Name & vbCr
    Next FF
    MsgBox FFNames
End If

This example formats the selection as Arial bold.

With Selection.Font
    .Name = "Arial"
    .Bold = True
End With

This example sets the name of the first list template used in the active document to "myList." A LISTNUM field (linked to the myList template) is then added at the insertion point. The field adopts the formatting of the myList template.

If ActiveDocument.ListTemplates.Count >= 1 Then
    ActiveDocument.ListTemplates(1).Name = "myList"
    Selection.Collapse Direction:=wdCollapseEnd
    ActiveDocument.Fields.Add Range:=Selection.Range, _
        Type:=wdFieldListNum, Text:="myList"
End If