Microsoft Office Tutorials and References
In Depth Information
Mail Merge: Using a Relative Path for Data Source
Mail Merge: Using a Relative Path for Data Source
This procedure lets you dynamically link to a data source in the same path as
the main merge document.
Example file:
Scenario: Word was originally designed to use absolute
paths to all linked files. Over the last few versions, support
for relative paths has been improved for some types of links,
but the path to a mail merge data source is still stored in
Word's binary file format as an absolute path. There is no
way to change mail merge to store a relative path to the data
source file.
This makes it difficult to distribute mail merge functionality;
every user who does not work on the same machine is forced
to relink manually to the data source.
The following set of macros takes on the burden of this task, linking to the data
source file located in the same folder as the main merge document. The user is
only prompted to search for the data source manually if it cannot be found.
View the Appendix to learn how to store this procedure
in a Standard module.
Option explicit¶
' * * * * *¶
Const FileName As String = "MailMergeData.doc"¶
' * * * * *¶
Sub LinkToSourceFile()¶
'Variable declaration¶
Dim Path As String¶
'Suppress the messages that display¶
'if Word can't find a data source¶
'Only works in Word 2002 and later¶
'See AutoClose macro for Word 97 / 2000¶
Application.DisplayAlerts = wdAlertsNone¶
'Construct the full path to the data file¶
Path = ActiveDocument.Path & "\" & FileName¶
'If the data file can be found, link to it¶
If Dir(Path) <> "" Then¶
ActiveDocument.MailMerge.OpenDataSource _¶
Search JabSto ::

Custom Search