VB6 Merge with Word
Posted on 2006-06-19
I have a Word template that I want to send data to from a VB6 app (it is not write protected and the final document gets saved as something else to preserve the formatting in the template). I have tried using Bookmarks, and it's fine on my PC with Word 2003 using the following:
psDoc = "C:\Temp\Master.dot"
'Create global word object
Set gobjWordDoc = gobjWordApp.Documents.Open(psDoc)
.ActiveDocument.Bookmarks("AgentData").Range.Text = txtAgentText
but when I distribute the app it gives an error:
compiled VB application has encountered a problem and needs to close.
Is there another (better) way to insert text into a pre-existing Word doc (maybe for older versions of Word) other than using bookmarks that might be version non-specific? Or the right way to use bookmarks if I'm not using them correctly.