PDA

Click to See Complete Forum and Search --> : Help with Mail Merge to Word Doc


alexdriver
Dec 15th, 2005, 09:35 AM
Hi,
I'm trying to Mail Merge to a Word Document from VB.
I have a Word Template with Mail Merge Fields.
The problem I have is that I need to insert an HTML table into one of the Mail Merge Fields, however it fails whenever I try to input from the text file.
I intended to create some VB code to find a particular Mail Merge Field and Insert the HTML in there.
However I can not seem to get it to work.
Here is the code I'm using:


Dim oApp As Word.Application
Dim oDoc As Word.Document

On Error GoTo errHandler

'Start a new document in Word
Set oApp = CreateObject("Word.Application")
Set oDoc = oApp.Documents.Open(s_Templates & TemplateFile)


With oDoc.MailMerge
.OpenDataSource Name:=s_TempFiles & "MergeData.txt" 'Specify your data source here
.Destination = wdSendToNewDocument
.Execute False
End With



oDoc.Close False
oApp.Documents(1).SaveAs (s_Drive & Subject & ".doc")
oApp.Documents(1).Close
' Release references.
oApp.Quit
Set oDoc = Nothing
Set oApp = Nothing

RobDog888
Dec 16th, 2005, 02:19 AM
Does s_TempFiles contain a valid filepath with an ending bakslash? "\".
Whats the error message?