
Macro for Mail Merge and Datasource...
Hi,
I need your help to create a VB macro which can create a formletter
mail merge document; select an Excel spreadsheet as the datasource
file from a directory listing; and prompt with the mailmerge helper.
So far, I have come up with the following code:
Sub GenLatinMailMerge
Documents.Open FileName:= _
"Latin Template.dot", ReadOnly:=True
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
' Add Excel Diploma HeaderSource Record.
With ActiveDocument.MailMerge
.OpenHeaderSource Name:="Latin Header Record.xls"
End With
Set dlg = Dialogs(wdDialogFileOpen)
With dlg
.Name = "*.xls"
.Show
End With
Select Case dlg
Case Is = -1
Case Is = -2
Case Is = 0
MsgBox "No files(s) selected!"
Case Else
dsname = ActiveDocument.MailMerge.DataSource.Name
MsgBox dsname
With ActiveDocument.MailMerge
.OpenDataSource Name:= dsname
End With
End Select
Set myMerge = ActiveDocument.MailMerge
If myMerge.State = wdMainAndDataSource Then
Dialogs(wdDialogMailMergeHelper).Show Else MsgBox "No MailMerge
Datasource selected!"
End Sub
The problem I am having is understanding how to store the "dsname"
information once a file has been selected from the list.
Thanks for any help you can provide.
Regards,
Greg