Document.MailMergeAfterRecordMerge Event

Occurs after each record in the data source successfully merges in a mail merge.

Namespace:  Microsoft.Office.Tools.Word
Assemblies:   Microsoft.Office.Tools.Word.v4.0.Utilities (in Microsoft.Office.Tools.Word.v4.0.Utilities.dll)
  Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)

Syntax

'Declaration
Event MailMergeAfterRecordMerge As EventHandler
event EventHandler MailMergeAfterRecordMerge

Examples

The following code example displays a message when the MailMergeAfterRecordMerge event is raised. This example is for an application-level add-in.

Private Sub DocumentMailMergeAfterRecordMerge()
    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    AddHandler vstoDoc.MailMergeAfterRecordMerge, AddressOf ThisDocument_MailMergeAfterRecordMerge
End Sub 

Private Sub ThisDocument_MailMergeAfterRecordMerge(ByVal sender As Object, ByVal e As EventArgs)
    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    Dim index As Object = 1
    System.Windows.Forms.MessageBox.Show(vstoDoc.MailMerge.DataSource.DataFields.Item(index).Value & _
        " is finished merging.")
End Sub
private void DocumentMailMergeAfterRecordMerge()
{
    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    vstoDoc.MailMergeAfterRecordMerge += new EventHandler(ThisDocument_MailMergeAfterRecordMerge);

}

void ThisDocument_MailMergeAfterRecordMerge(object sender, EventArgs e)
{
    object index = 1;
    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    System.Windows.Forms.MessageBox.Show(vstoDoc.MailMerge.DataSource.DataFields.get_Item(ref index).Value
         + " is finished merging.");
}

.NET Framework Security

See Also

Reference

Document Interface

Microsoft.Office.Tools.Word Namespace