XMLSelectionChange Event

Microsoft Word Visual Basic

Show All Show All

XMLSelectionChange Event

Occurs when the parent XML node of the current selection changes.

Private Sub object_XMLSelectionChange(Sel, OldXMLNode, NewXMLNode, Reason)

object    An object of type Application that has been declared in a class module by using the WithEvents keyword. For more information about using events with the Application object, see Using Events with the Application Object.

Sel   Selection. The text selected, including XML elements. If no text is selected, the Sel parameter returns either nothing or the first character to the right of the insertion point.

OldXMLNode   XMLNode. The XML node from which the insertion point is moving.

NewXMLNode   XMLNode. The XML node to which the insertion point is moving.

Reason   Required Long. The reason why the selection has changed. Can be any of the wdXMLSelectionChange constants.

wdXMLSelectionChange can be any of the following wdXMLSelectionChange constants.

wdXMLSelectionChangeReasonDeleteSelection has been deleted.
wdXMLSelectionChangeReasonInsertText has been inserted into the selection.
wdXMLSelectionChangeReasonMoveInsertion point has been moved.

Example

The following example validates a newly added XML element when a new element is inserted into the document.

    Private Sub Wrd_XMLSelectionChange(ByVal Sel As Selection, _
        ByVal OldXMLNode As XMLNode, ByVal NewXMLNode As XMLNode, _
        Reason As Long)
        
    Dim intResponse As Integer
    
    If Reason = wdXMLSelectionChangeReasonInsert Then
        If Not NewXMLNode Is Nothing Then
            NewXMLNode.Validate
        End If
    End If
    
End Sub