WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Word

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Word Mail Merge

 Keywords:  Word Mail Merge OLE

Question:

Has anyone done anything with Word in automating a mail merge?

Answer:

The following code works for me, as long as you have created a 'skeleton' word document with an appropriate input 'csv' file -
appWord = objectopen("Word.Application")
Documents = appWord.Documents
Documents.Open(skeletonDoc)
activeDoc = appWord.ActiveDocument
mailMerge = activeDoc.MailMerge
mailMerge.Destination = 0
mailMerge.Execute
oDOC = appWord.Application
oDOC.ChangeFileOpenDirectory(pathToSaveMergedDocIn)
activeDoc = appWord.ActiveDocument
activeDoc.SaveAs(nameToSaveMergedDocAs)
activeWin = appWord.ActiveWindow
activeWin.Close
activeWin= appWord.ActiveWindow
activeWin.Close

objectclose(mailmerge)
objectclose(activeWin)
objectclose(activeDoc)
objectclose(Documents)
objectclose(appWord)

Article ID:   W15666
File Created: 2003:05:13:11:29:24
Last Updated: 2003:05:13:11:29:24