Udostępnij za pośrednictwem


Document.MailMergeDataSourceLoad Event (2007 System)

Occurs when the data source is loaded for a mail 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 MailMergeDataSourceLoad As EventHandler
'Usage
Dim instance As Document 
Dim handler As EventHandler 

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

Examples

The following example displays a message when the data source for a mail merge is loaded.

This version is for a document-level customization.

Private Sub DocumentMailMergeDataSourceLoad()
    AddHandler Me.MailMergeDataSourceLoad, AddressOf ThisDocument_MailMergeDataSourceLoad
End Sub 

Private Sub ThisDocument_MailMergeDataSourceLoad(ByVal sender As Object, ByVal e As EventArgs)
    Dim index As Object = 1
    MessageBox.Show(Me.MailMerge.DataSource.DataFields.Item(index).Value & _
        " is loading.")
End Sub
private void DocumentMailMergeDataSourceLoad()
{
    this.MailMergeDataSourceLoad += new EventHandler(ThisDocument_MailMergeDataSourceLoad);
}

void ThisDocument_MailMergeDataSourceLoad(object sender, EventArgs e)
{
    object index = 1;
    MessageBox.Show(this.MailMerge.DataSource.DataFields.get_Item(ref index).Value
         + " is loading.");
}

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

Private Sub DocumentMailMergeDataSourceLoad()
    Dim vstoDoc As Document = Me.Application.ActiveDocument.GetVstoObject()
    AddHandler vstoDoc.MailMergeDataSourceLoad, AddressOf ThisDocument_MailMergeDataSourceLoad
End Sub 

Private Sub ThisDocument_MailMergeDataSourceLoad(ByVal sender As Object, ByVal e As EventArgs)
    Dim vstoDoc As Document = Me.Application.ActiveDocument.GetVstoObject()
    Dim index As Object = 1
    System.Windows.Forms.MessageBox.Show(vstoDoc.MailMerge.DataSource.DataFields.Item(index).Value & _
        " is loading.")
End Sub
private void DocumentMailMergeDataSourceLoad()
{
    Document vstoDoc = this.Application.ActiveDocument.GetVstoObject();
    vstoDoc.MailMergeDataSourceLoad += new EventHandler(ThisDocument_MailMergeDataSourceLoad);
}

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

.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.