View Single Post
  #2   Report Post  
Peter Jamieson
 
Posts: n/a
Default

You can use VBA to get the path name of the .doc and use it to construct the
path name of the .txt, then issue an OpenDataSource call in an AutoOpen
macro to open that data source when the document opens. However, you should
also make sure that the document is saved without a connection to the data
source, and that means that you will lose any sorting or filtering and you
will need to specify the appropriate bit of SQL in the OpenDataSource call.

e.g., your macro might be along the following lines (I haven't tested this
one and you will probably need to modify the OpenDataSource):

Sub autoopen()
Dim sDSFN As String
sDFSN = "data.txt"
With ActiveDocument.Mailmerge
' Change the document type to the one you want
.MainDocumentType = wdFormLetters
.OpenDataSource _
ActiveDocument.Path & "\" & sDFSN, _
SQLStatement:="SELECT * FROM " & sDFSN
' Change the destination to the one you want
.Destination = wdSendToNewDocument
' Uncomment the next line if you want to do the merge
.Execute
End With
End Sub

Peter Jamieson

"MCubitt" wrote in message
...
I have created a merge in MS Word which uses a text file as its data
source.

When I start the document, and review the merge details, it shows the Data
Source as Data: C:\folder1\data.txt

However, I want to transport the Word and data.txt file which could end up
on another drive/folder location (but always with the Word and data.txt in
the same place, not separated).

What I really want is Data: ..\data.txt so it looks inside the current
folder.

Is this possible please?