Share via


Document.MailMergeBeforeMerge Event (2007 System)

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

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

Syntax

'Declaration
Public Event MailMergeBeforeMerge As EventHandler
'Usage
Dim instance As Document 
Dim handler As EventHandler 

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

Remarks

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

Examples

The following code example displays a message before any manual mail merge is run.

This version is for a document-level customization.

Private Sub DocumentMailMergeBeforeMerge()
    AddHandler Me.MailMergeBeforeMerge, AddressOf ThisDocument_MailMergeBeforeMerge
End Sub 

Private Sub ThisDocument_MailMergeBeforeMerge(ByVal sender As Object, ByVal e As EventArgs)
    MessageBox.Show("Your mail merge on " & Me.Name & " is now starting.")
End Sub
private void DocumentMailMergeBeforeMerge()
{
    this.MailMergeBeforeMerge += new EventHandler(ThisDocument_MailMergeBeforeMerge);
}

void ThisDocument_MailMergeBeforeMerge(object sender, EventArgs e)
{
    MessageBox.Show("Your mail merge on "
        + this.Name + " is now starting.");
}

This version is for an application-level add-in.

Private Sub DocumentMailMergeBeforeMerge()
    Dim vstoDoc As Document = Me.Application.ActiveDocument.GetVstoObject()
    AddHandler vstoDoc.MailMergeBeforeMerge, AddressOf ThisDocument_MailMergeBeforeMerge
End Sub 

Private Sub ThisDocument_MailMergeBeforeMerge(ByVal sender As Object, ByVal e As EventArgs)
    Dim vstoDoc As Document = Me.Application.ActiveDocument.GetVstoObject()
    System.Windows.Forms.MessageBox.Show("Your mail merge on " & vstoDoc.Name & " is now starting.")
End Sub
private void DocumentMailMergeBeforeMerge()
{
    Document vstoDoc = this.Application.ActiveDocument.GetVstoObject();
    vstoDoc.MailMergeBeforeMerge += new EventHandler(ThisDocument_MailMergeBeforeMerge);
}

void ThisDocument_MailMergeBeforeMerge(object sender, EventArgs e)
{
    Document vstoDoc = this.Application.ActiveDocument.GetVstoObject();
    System.Windows.Forms.MessageBox.Show("Your mail merge on "
        + vstoDoc.Name + " is now starting.");
}

.NET Framework Security

See Also

Reference

Document Class

Document Members

Microsoft.Office.Tools.Word Namespace

Change History

Date

History

Reason

July 2008

Added a version of the code example for an application-level add-in.

SP1 feature change.