共用方式為


Document.MailMergeBeforeMerge Event

Definition

Occurs when a merge is executed, before any records merge.

public:
 event EventHandler ^ MailMergeBeforeMerge;
event EventHandler MailMergeBeforeMerge;
member this.MailMergeBeforeMerge : EventHandler 
Event MailMergeBeforeMerge As EventHandler 

Event Type

Examples

The following code example displays a message before any manual mail merge is run. This example is for an application-level add-in.

private void DocumentMailMergeBeforeMerge()
{
    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    vstoDoc.MailMergeBeforeMerge += new EventHandler(ThisDocument_MailMergeBeforeMerge);
}

void ThisDocument_MailMergeBeforeMerge(object sender, EventArgs e)
{
    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    System.Windows.Forms.MessageBox.Show("Your mail merge on "
        + vstoDoc.Name + " is now starting.");
}
Private Sub DocumentMailMergeBeforeMerge()
    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    AddHandler vstoDoc.MailMergeBeforeMerge, AddressOf ThisDocument_MailMergeBeforeMerge
End Sub

Private Sub ThisDocument_MailMergeBeforeMerge(ByVal sender As Object, ByVal e As EventArgs)
    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    System.Windows.Forms.MessageBox.Show("Your mail merge on " & vstoDoc.Name & " is now starting.")
End Sub

Remarks

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

Applies to