NodeValue Property

Microsoft Word Visual Basic

NodeValue Property

Sets or returns a String that represents the value of an attribute.

expression.NodeValue

expression    Required. An expression that returns an XMLNode object.

Remarks

An XMLNode object can be either an XML element or an attribute of an element. Use the NodeType property to determine which type of node you are working with.

For XMLNode objects with a NodeType value of wdXMLNodeElement, the NodeValue property returns nothing.

Example

The following example adds the id attribute to the book element in the active document, and then sets the value of the attribute.

    Sub AddIDAttribute()
    Dim objElement As XMLNode
    Dim objAttribute As XMLNode

    For Each objElement In ActiveDocument.XMLNodes
        If objElement.NodeType = wdXMLNodeElement Then
            If objElement.BaseName = "book" Then
                
                Set objAttribute = objElement.Attributes _
                    .Add("id", objElement.NamespaceURI)

                objAttribute.NodeValue = "ISBN: 0964719908"
                
                Exit For
            End If
        End If
    Next
End Sub