Here is the code
' BFE 4/25/07 XXXXXX. Change the macro to work in the current directory,
rather than
' hardcoded to C:\Datatel. Also update from the old Word95 basic code.
' This macro is linked to the Alt-M key. It will open DATATEL.DOC, which was
just downloaded
' to the client PC, update the merge data source to DATATEL.TXT which was
also just downloaded,
' and then run the merge.
Public Sub MAIN()
Dim objDatatelDot As Word.Document
Dim objDoc As Word.Document
Dim strCurPath As String
' Save object pointer to this document, so we can close it later
Set objDatatelDot = ActiveDocument
' Get path of this document
strCurPath = ActiveDocument.Path
If Right(strCurPath, 1) <> "\" Then strCurPath = strCurPath & "\"
' DATATEL.DOC and this document are in the same directory, which may vary
from user to user.
Set objDoc = Documents.Open(strCurPath & "DATATEL.DOC")
' DATATEL.DOC was setup with merge data source HEADER.DOC, which contained
only the field names.
' Now switch it to DATATEL.TXT, which will have the actual data.
DATATEL.TXT has been downloaded
' to the same directory as this document.
' (Why not just DATATEL.TXT for both setup and actual merge? Makes sense,
but need to keep this
' method now for backward compatibility.)
' LinkToSource means requery the data source each time this doc is opened.
objDoc.MailMerge.OpenDataSource Name:=strCurPath & "DATATEL.TXT",
LinkToSource:=True
' Run the merge
objDoc.MailMerge.Execute
' Close DATATEL.DOC and DATATEL.DOT. The new document created by the merge
will still be open.
' These Files are deleted by Colleague as soon as the user indicates the
merge is complete,
' but save in case the user wants to save them before returning to
Colleague.
' 10/09/2007 AHH XXXXXXXXXXXXX / ENV_SCR_15958
' Both objDoc.Close stmts need to be commented out to prevent the error msg.
' objDoc.Close SaveChanges:=True
' objDatatelDot.Close SaveChanges:=True
' Previous Code, which was the macro language from Word 95, still
supported for backward
' compatibility through the WordBasic object. Now replaced with equivalent
VBA.
'WordBasic.FileList 1
'WordBasic.FileOpen Name:="C:\DATATEL\DATATEL.DOC"
'WordBasic.MailMergeOpenDataSource Name:="C:\DATATEL\DATATEL.TXT",
ConfirmConversions:=0, ReadOnly:=0, LinkToSource:=1, AddToMru:=0,
PasswordDoc:="", PasswordDot:="", Revert:=0, WritePasswordDoc:="",
WritePasswordDot:="", Connection:="", SQLStatement:="", SQLStatement1:=""
'WordBasic.MailMerge CheckErrors:=1, Destination:=0, MergeRecords:=0,
From:="", To:="", Suppression:=0, MailMerge:=1, MailSubject:="",
MailAsAttachment:=0, MailAddress:=""
End Sub