MailMerge.DataSource
Returns a MailMergeDataSource object that refers to the data source attached to a mail merge main document. Read-only.
This example displays the name of the data source attached to the active document.
If ActiveDocument.MailMerge.DataSource.Name <> "" Then _
MsgBox ActiveDocument.MailMerge.DataSource.Name
This example displays the next record from the data source attached to Main.doc.
ActiveDocument.ActiveWindow.View.ShowFieldCodes = False
With Documents("Main.doc").MailMerge
.ViewMailMergeFieldCodes = False
.DataSource.ActiveRecord = wdMailMergeActiveRecord.wdNextRecord
End With
MailMergeDataSource Object
Use the DataSource property to return the MailMergeDataSource object.
The following example displays the name of the data source associated with the active document.
If ActiveDocument.MailMerge.DataSource.Name <> "" Then
MsgBox ActiveDocument.MailMerge.DataSource.Name
End If
The following example displays the field names in the data source associated with the active document.
For Each aField In ActiveDocument.MailMerge.DataSource.FieldNames
MsgBox aField.Name
Next aField
The following example opens the data source associated with Form letter.doc and determines whether the FirstName field includes the name "Kate."
With Documents("Form letter.doc").MailMerge
.EditDataSource
If .DataSource.FindRecord(FindText:="Kate", _
Field:="FirstName") = True Then
MsgBox "Data was found"
End If
End With
MailMerge.EditDataSource
Opens or switches to the mail merge data source.
If the data source is a Word document, this method opens the data source (or activates the data source if it's already open).
If Word is accessing the data through dynamic data exchange (DDE)— using an application such as Microsoft Excel or Microsoft Access - this method displays the data source in that application.
If Word is accessing the data through open database connectivity (ODBC), this method displays the data in a Word document. Note that if Microsoft Query is installed, a message appears, providing the option to display Microsoft Query instead of converting data.
Example
This example opens or activates the data source attached to the document named "Sales.doc."
Documents("Sales.doc").MailMerge.EditDataSource
This example opens or activates the attached data source if the data source is a Word document.
Dim dsMain As MailMergeDataSource
Set dsMain = ActiveDocument.MailMerge.DataSource
If dsMain.Type = wdMailMergeDataSource.wdMergeInfoFromWord Then
ActiveDocument.MailMerge.EditDataSource
End If
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext