Macro for Mail Merge and Datasource... 
Author Message
 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



Mon, 05 Sep 2005 02:15:57 GMT  
 Macro for Mail Merge and Datasource...
Hi Greg,

Quote:
> The problem I am having is understanding how to store the "dsname"
> information once a file has been selected from the list.

Store it for what purpose?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan 24
2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :-)



Tue, 27 Sep 2005 23:49:25 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Mail Merge - Word was unable to open the datasource

2. QueryString length of mail merge datasource.

3. MS Word 97 Mail Merge with Oracle Datasource?

4. MS Word 97 Mail Merge with Oracle Datasource?

5. Mail Merge BarCodes / Mail Merge Insertion Point

6. Word mail merge and Access macros

7. Mail Merge to a pre-existing word document via a macro

8. Office XP Mail Merge issue Insertdatabase issue and problems with copying a macro

9. Macro for mail merge in Outlook

10. macro for automatic mail merge

11. Macro to automate mail merge

12. Mail Merge Doc With macro for fax printer driver

 

 
Powered by phpBB® Forum Software