Hello! I'm doing a mail merge with a Word document and here's the code that I have (got it off the Microsoft website after doing a search here on the forums):
When I try to call the function to see what it'll do, it gives me a compile error saying User-defined type not defined and it highlights the 'Dim objWord As Word.Document'.
Why am I getting this?
Thanks!
David Somers
Code:
Private Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("G:\Past Due Notice - 5th.doc", "Word.Document")
' Make Word invisible
objWord.Application.Visible = False
' Set the mail merge data source as the database
objWord.MailMerge.OpenDataSource Name:="G:\temp5 _
\FPMLLCNEW_SB.mdb", LinkToSource:=True, _
Connection:="TABLE tblLateNotice", SQLStatement:="Select * from [tblLateNotice]"
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute
' The following line must follow the Execute statement because the
' PrintBackground property is available only when a document window is
' active. Without this line of code, the function will end before Word
' can print the merged document.
objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut
When I try to call the function to see what it'll do, it gives me a compile error saying User-defined type not defined and it highlights the 'Dim objWord As Word.Document'.
Why am I getting this?
Thanks!
David Somers