Megosztás a következőn keresztül:


Document.MailMergeBeforeRecordMerge Event

Occurs as a merge is executed for the individual records in a 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 MailMergeBeforeRecordMerge As CancelEventHandler
event CancelEventHandler MailMergeBeforeRecordMerge

Remarks

To stop the mail merge process for the current record, set the Cancel argument of the provided CancelEventArgs to true.

Examples

The following code example displays a message before the first record is merged. This example is for an application-level add-in.

Private Sub DocumentMailMergeBeforeRecordMerge()
    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    AddHandler vstoDoc.MailMergeBeforeRecordMerge, AddressOf ThisDocument_MailMergeBeforeRecordMerge
End Sub 

Private Sub ThisDocument_MailMergeBeforeRecordMerge(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
    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 now merging.")
End Sub
private void DocumentMailMergeBeforeRecordMerge()
{
    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    vstoDoc.MailMergeBeforeRecordMerge += new System.ComponentModel.CancelEventHandler(ThisDocument_MailMergeBeforeRecordMerge);
}

void ThisDocument_MailMergeBeforeRecordMerge(object sender, System.ComponentModel.CancelEventArgs e)
{
    object index = 1;
    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    System.Windows.Forms.MessageBox.Show(vstoDoc.MailMerge.DataSource.DataFields[index].Value + 
         " is now merging.");
}

.NET Framework Security

See Also

Reference

Document Interface

Microsoft.Office.Tools.Word Namespace