Re: Macro to open Word and Start Mail Merge
jtemp59: You may need to open a new post for this, so don't be surprised if you get dinged by the moderator.
I am by no means an expert, so, for what it is worth:
A) Make sure that you have set your reference to the Microsoft Word XX.XX Object Library (pick the highest number available)
C) Set up the Word merge file, then just tell Excel to run the merge. Always works best for me.
B) From what I can see, you are not declaring your word document correctly. The application handles the word "window", but it does not control what happens inside the document.
Set up the application - then set up the document. But don't to use the application where you should be using the document property. Something like this:
' Setting up the Word application Dim wdApp As Word.Application
On Error Resume Next
' open the mail merge layout file
Dim wdDoc As Word.Document '<== this is what I don't see in your code.
' Error handling
Set wdApp = GetObject(, "word.application")
If wdApp Is Nothing Then
Set wdApp = GetObject("C:YourWordDocumentObject.docx", "word.application") ' <== Just tells Excel where to go to find the file if the merge file is not open on your desktop
End If
On Error GoTo 0
' Now you start opening the Word application and the document
With wdApp
' Set wdDoc = .Documents.Open
Set wdDoc = .Documents.Open(Filename:="C:YourWordDocToOpen.docx") '<==this opens the document so you can manipulate it.
wdDoc.Application.Visible = True
' Just telling word how to run the merge
With wdDoc.MailMerge
.MainDocumentType = wdFormLetters
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.Execute Pause:=False
End With
wdDoc.Application.Visible = True
' Sends to the default printer once created
wdDoc.PrintOut
' housekeeping
wdDoc.Close SaveChanges:=False
Set wdDoc = Nothing
End With
Display More
Hope that at least gives you some ideas to trouble shoot the problem. If not - open a post, and be clear what type of debug you are getting.