Document.XMLAfterInsert Event (2007 System)

Occurs when a user adds a new XML element to a document. If more than one element is added to the document at the same time (for example, when cutting and pasting XML), the event is raised for each element that is inserted.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v9.0 (in Microsoft.Office.Tools.Word.v9.0.dll)

Syntax

'Declaration
Public Event XMLAfterInsert As DocumentEvents2_XMLAfterInsertEventHandler
'Usage
Dim instance As Document 
Dim handler As DocumentEvents2_XMLAfterInsertEventHandler 

AddHandler instance.XMLAfterInsert, handler
public event DocumentEvents2_XMLAfterInsertEventHandler XMLAfterInsert
public:
 event DocumentEvents2_XMLAfterInsertEventHandler^ XMLAfterInsert {
    void add (DocumentEvents2_XMLAfterInsertEventHandler^ value);
    void remove (DocumentEvents2_XMLAfterInsertEventHandler^ value);
}
JScript does not support events.

Examples

The following code example demonstrates event handlers for the XMLAfterInsert and XMLBeforeDelete events. The code displays a message before an XMLNode is deleted from the document and after an XMLNode is added to the document. To test this code example, use the XML Structure task pane to add XML elements to the document, and then experiment with the Undo Typing and Redo Typing options on the Edit menu. This example assumes that the current document is mapped to a valid XML schema.

This example is for a document-level customization.

Private Sub DocumentXMLBeforeAndAfterInsert()
    AddHandler Me.XMLAfterInsert, AddressOf ThisDocument_XMLAfterInsert
    AddHandler Me.XMLBeforeDelete, AddressOf ThisDocument_XMLBeforeDelete
End Sub  

Private Sub ThisDocument_XMLBeforeDelete(ByVal DeletedRange As Word.Range, ByVal OldXMLNode As Word.XMLNode, ByVal InUndoRedo As Boolean)
    If InUndoRedo Then
        MessageBox.Show(OldXMLNode.BaseName & " element is about to be deleted as a result" _
            & " of an undo or redo operation.")
    Else
        MessageBox.Show(OldXMLNode.BaseName & " element is about to be deleted.")
    End If 
End Sub 

Private Sub ThisDocument_XMLAfterInsert(ByVal NewXMLNode As Word.XMLNode, ByVal InUndoRedo As Boolean)
    If InUndoRedo Then
        MessageBox.Show(NewXMLNode.BaseName & " element was " & "inserted as a result " _
            & "of an undo or redo operation.")
    Else
        MessageBox.Show(NewXMLNode.BaseName & " element was inserted.")
    End If 
End Sub
private void DocumentXMLBeforeAndAfterInsert()
{
    this.XMLAfterInsert +=
        new Word.DocumentEvents2_XMLAfterInsertEventHandler(
        ThisDocument_XMLAfterInsert);

    this.XMLBeforeDelete +=
        new Word.DocumentEvents2_XMLBeforeDeleteEventHandler(
        ThisDocument_XMLBeforeDelete);
}

void ThisDocument_XMLBeforeDelete(Word.Range DeletedRange,
    Word.XMLNode OldXMLNode, bool InUndoRedo)
{
    if (InUndoRedo)
    {
        MessageBox.Show(OldXMLNode.BaseName +
            " element is about to be deleted as a result" +
            " of an undo or redo operation.");
    }
    else
    {
        MessageBox.Show(OldXMLNode.BaseName +
            " element is about to be deleted.");
    }
}

void ThisDocument_XMLAfterInsert(Word.XMLNode NewXMLNode,
    bool InUndoRedo)
{
    if (InUndoRedo)
    {
        MessageBox.Show(NewXMLNode.BaseName + " element was " +
            "inserted as a result of an undo or redo operation.");
    }
    else
    {
        MessageBox.Show(NewXMLNode.BaseName + " element was inserted.");
    }
}

.NET Framework Security

See Also

Reference

Document Class

Document Members

Microsoft.Office.Tools.Word Namespace