|
-
Dec 15th, 2005, 10:35 AM
#1
Thread Starter
New Member
Help with Mail Merge to Word Doc
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
-
Dec 16th, 2005, 03:19 AM
#2
Re: Help with Mail Merge to Word Doc
Does s_TempFiles contain a valid filepath with an ending bakslash? "\".
Whats the error message?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|