I am performing a mail merge from Excel, which works exactly as I need. My issue is that I am wanting to keep word hidden from the user, and that is not occurring. I end up with an empty instance of word on the screen that I do not want.
This is my syntax - why am I unable to completely hide and close word when the process is finished?
Dim wdapp As Word.Application, wdDoc As Word.Document, wdMaiMerge As Word.MailMerge
'Setting refs
Set wdapp = CreateObject("Word.Application")
Set wdDoc = wdapp.Documents.Open(wdpath)
Set wdMailMerge = wdDoc.MailMerge
'hiding display from user
wdapp.Visible = False
'Setting mail merge
With wdMailMerge
.OpenDataSourcexxxx, ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False
.Execute
End With
'Finishing
Set wdapp = Nothing
wdapp.Quit
You're not telling Word what query to use or what to do with either the document you're using for the mailmerge once you've used it or the mailmerge output! And, if the document you're opening is a mailmerge main document, your code will hang at that point - you need to suppress that and supply all the SQL code yourself. For example: