How to make mail merge independent from source file path?

  • Thread starter Mohammad Fouz Salah
  • Start date
M

Mohammad Fouz Salah

When moving the files that have merge fields to another location or media, of
course with the source file, the path changes and the word file wouldn't be
able to locate the source new location. How can I make the mail merge path
independent, so I can burn both on CD, for instance, and keep the merge
feature.
 
P

Peter Jamieson

The only way to do it as far as I know is
a. disconnect the mail merge main document from its data source
b. use an AutoOpen macro to connect it again. The macro can discover the
document's folder.

Unfortunately, in order to do that,
c. the destination system has to be prepared according to the following KB
article:

http://support.microsoft.com/default.aspx?scid=kb;en-us;825765

d. the destination system also has to be set up so that the AutoOpen macro
will run.

Even then, you will probably have difficulty getting the merge to work
/directly/ from the CD. Generally speaking, with Word, the user needs to
copy the files off the CD and onto a writable disk before Word will work
properly.

You can do (a) using e.g.

ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument

in th VB Editor's immediate window

You will lose information about the /type/ of merge, the location of the
data source, any sort/filter options, and the merge destination, but the
merge field codes will remain. You can find out what Word thinks the file
name, connection string and query are using the following in the immediate
window:

print ActiveDocument.Mailmerge.DataSource.Name
print ActiveDocument.Mailmerge.DataSource.ConnectString
print ActiveDocument.Mailmerge.DataSource.QueryString

You can (probably!) do (b) using something like the following macro, but you
will need to changes stuff depending on the type of data source, and the
code that creates the full path name of the data source probably needs to be
more robust:

Sub AutoOpen()
Dim strDataSource As String
Dim strConnection As String
Dim strQuery As String

' this is a simple example for a data source which is a Word document
' set this to be the file name of your data source
strDataSource = "kt.doc"

' set this to be the connection string for your data source
'strConnection = ""

' set this to be the query for your data source
' strQuery = ""

With ActiveDocument
strDataSource = .Path & "\" & strDataSource
' for a Word document as data source, we just need the path name
With .MailMerge
.OpenDataSource _
Name:=strDataSource
' use the type you need
.MainDocumentType = wdFormLetters
' use the destination you need
.Destination = wdSendToNewDocument

' NB the above code does not execute the merge.
End With
End With
End Sub

Peter Jamieson
 

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