Microsoft Office Tutorials and References
In Depth Information
Mail Merge: Using a Relative Path for Data Source
Note: The macro recorder often (but not always) creates an 'OpenDataSource'
method that works when it is run in a macro. The problems are largely
restricted to Word 2002 and Word 2003 OLE DB connections (the default).
Also keep in mind that 'OpenDataSource' does not necessarily work the same
across all versions of Word, unless the data source is a Word document.
For all of the above situations, when not using Word documents or text files as
the data source, ODBC connections are the most reliable. In order to force
Word to create an ODBC connection:
In Word 97 and Word 2000, activate the Select Method checkbox in the
Open Data Source dialog box.
In Word 2002 and Word 2003 Confirm Conversions on Open must be
activated in Tools | Options | General before using the Open Data
Source dialog box.
In all cases, select ODBC in the list that follows. If the desired data
table does not appear in the next dialog box, click Options and activate
all the checkboxes in the next screen.
Here is an 'OpenDataSource' method recorded in Word 2003. Note how the file
path is used in two places. In both instances, the file path needs to be replaced
with the variable Path. If the macro should run under Word 97 or Word 2000,
delete the last argument SubType:= wdMergeSubTypeOther, because this
argument is not recognized by these versions.
ActiveDocument.MailMerge.OpenDataSource _¶
Name:="C:\Documents and Settings\User\My Documents\SalesData.xls", _¶
ConfirmConversions:=False, _¶
ReadOnly:=False, _¶
LinkToSource:=True, _¶
AddToRecentFiles:=False, _¶
PasswordDocument:="", _¶
PasswordTemplate:="", _¶
WritePasswordDocument:="", _¶
WritePasswordTemplate:="", _¶
Revert:=False, _¶
Format:=wdOpenFormatAuto, _¶
Connection:= _¶
"DSN=Excel Files;DBQ=C:\Documents and Settings\User\My
Documents\SalesData.xls;DriverId=790;MaxBufferSize=2048;PageTimeout=5;". _¶
SQLStatement:="SELECT * FROM `Sheet1$`", _¶
SQLStatement1:="", SubType:=wdMergeSubTypeOther¶
Search JabSto ::

Custom Search