Table of contents
TOC
Collapse the table of content
Expand the table of content

Application.MailMergeDataSourceLoad Event (Publisher)

office 365 dev account|Last Updated: 8/24/2017
|
3 Contributors

Occurs when the data source is loaded for a mail merge.

Syntax

expression. MailMergeDataSourceLoad( Doc)

_expression_A variable that represents an Application object.

Parameters

NameRequired/OptionalData TypeDescription
DocRequiredDocumentThe mail merge main document.

Remarks

To access the Application object events, declare an Application object variable in the General Declarations section of a code module. Then set the variable equal to the Application object for which you want to access events. For information about using events with the Microsoft Publisher Application object, see Using Events with the Application Object.

Example

This example displays a message with the data source file name when the data source starts loading.

Private Sub MailMergeApp_MailMergeDataSourceLoad(ByVal Doc As Document) 
 Dim strDSName As String 
 Dim intDSLength As Integer 
 Dim intDSStart As Integer 

 'Pull out of the Name property (which includes path and file name) 
 'only the file name using Visual Basic commands Len, InStrRev, and Right 
 intDSLength = Len(ActiveDocument.MailMerge.DataSource.Name) 
 intDSStart = InStrRev(ActiveDocument.MailMerge.DataSource.Name, "\") 
 intDSStart = intDSLength - intDSStart 
 strDSName = Right(ActiveDocument.MailMerge.DataSource.Name, intDSStart) 

 'Deliver a message to user when data source is loading 
 MsgBox "Your data source, " &; strDSName &; ", is now loading." 
End Sub

For this event to occur, you must place the following line of code in the General Declarations section of your module and run the following initialization routine.

Private WithEvents MailMergeApp As Application 

Sub InitializeMailMergeApp() 
 Set MailMergeApp = Publisher.Application 
End Sub

See also

Concepts

Application Object

© 2018 Microsoft