I have sweated for months on how to do this in Word 2000, with the source a
tab delimited txt file, and have finally come up with a solution.
Roughly speaking, I inserted the Title field into the document with the
merge field names inside it within quotes, ie
{TITLE "{ MERGEFIELD <field name from source doc>} { MERGEFIELD <another
field name from source doc>} on { MERGEFIELD <a date field name from source
doc>}"\* MERGEFORMAT}
This places the chosen fields into the Document Properties Title field.
A little VBA (my first real attempt at writing some!) was then written:
Sub Merge_with_title_as_Subject
Dim count As Integer
count = 1
ChangeFileOpenDirectory "C:\<path to file already created as a merge
document>"
Documents.Open FileName:="<merge document>.doc"
Do
With ActiveDocument.MailMerge
.Destination = wdSendToEmail
.MailAsAttachment = True
.MailAddressFieldName = "<email address field in source file>"
.MailSubject = "Site Visit Report for " & _
ActiveDocument.BuiltInDocumentProperties(wdPropertyTitle)
.SuppressBlankLines = True
With .DataSource
.FirstRecord = count
.LastRecord = count
End With
.Execute Pause:=True
.DataSource.ActiveRecord = wdNextRecord
count = count + 1
End With
Loop Until ActiveDocument.MailMerge.DataSource.LastRecord =
ActiveDocument.MailMerge.DataSource.ActiveRecord
ActiveDocument.Close wdDoNotSaveChanges
Application.Quit
End Sub
My requirement was to have this macro auto run from a Scheduled Tasks
copmmand, to then open the document to be merged (which is already associated
with the data source), merge the first record, then the next then the next
and then shut down Word, all unattended. As the merged document does not get
saved and thus is not given a filename, this was the only way I could see of
doing it.
Now, whereas this works, I daresay that my coding is pretty ropey - if
anyone cares to tidy it up, I'd be most grateful (that's if anyone /sees/
this post, having answered a post that's more than six months old!)
Anyhoo, the same principal should be useable for a merge whatever the
source, I would have thought
Simon Ayling