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:
VB Code:
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




Reply With Quote