QUERY: Word mail merge data sources

E

eugene

I have a mail merge that I run via a macro in Word 2000 - 2007
depending on client installations. The mail merge uses text files as
the default data source for the word templates.

One of the problems we have is when clients change the location of
their templates the data source needs to be relinked to the word
document/template.

Does anybody know whether it is possible to relink the word document/
template to a default data source via macro or otherwise without
needing to open each word document/template and manually doing this?
 
D

Doug Robbins - Word MVP

The following should do it:

Public Sub BatchAttachDataSource()
Dim fd As FileDialog
Dim myFile As String
Dim PathToUse As String
Dim DataSource As String
Dim myDoc As Document
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.Title = "Select the DataSource"
With fd
.AllowMultiSelect = False
If .Show = -1 Then
DataSource = .SelectedItems(1)
End If
End With
Set fd = Nothing
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
fd.Title = "Select the folder containing the mail merge main documents."
With fd
.AllowMultiSelect = False
If .Show = -1 Then
PathToUse = .SelectedItems(1) & "\"
End If
End With
Set fd = Nothing
Documents.Close SaveChanges:=wdPromptToSaveChanges
'Set the directory and type of file to batch process
myFile = Dir$(PathToUse & "*.doc")
While myFile <> ""
'Open document and attach the data source
Set myDoc = Documents.Open(PathToUse & myFile)
myDoc.MailMerge.OpenDataSource DataSource
'Close the modified document after saving changes
myDoc.Close SaveChanges:=wdSaveChanges
'Next file in folder
myFile = Dir$()
Wend
End Sub
 
E

eugene

Hi Doug,

Thanks for your response - one question though - which Object Library
allows me to declare a FileDialog?

Thanks
Eugene

The following should do it: EDIT
Hope this helps,

Doug Robbins - Word MVP
dkr[atsymbol]mvps[dot]org


 
G

Graham Mayor

Microsoft Office 12.0 Object Library (where 12 is the Word version - here
Word 2007)

Hi Doug,

Thanks for your response - one question though - which Object Library
allows me to declare a FileDialog?

Thanks
Eugene

The following should do it: EDIT
Hope this helps,

Doug Robbins - Word MVP
dkr[atsymbol]mvps[dot]org


 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top