Trying to late bind with the following code, but it gives me an error when running saying that wdFormLetters is not a defined variable. I'm guessing that with late binding, referencing properties is a no-go? It's not processing any of the code in this sub. It throws the error right away.
Here is a snippet of the code:
Code:
Dim oWord As Object
Dim oWdoc As Object
Set oWord = CreateObject("Word.Application")
Dim wdInputName As String
Dim wdOutputName As String
Dim outFileName As String
Const msoFileDialogFilePicker As Long = 3
Dim objDialog As Object
On Error GoTo PROC_ERR
' Set Template Path
'------------------------------------------------
Set objDialog = Application.FileDialog(msoFileDialogFilePicker)
With objDialog
.AllowMultiSelect = False
.InitialFileName = CurrentProject.Path & "\MailMergeDocs\"
.Show
If .SelectedItems.Count = 0 Then
MsgBox "No file selected."
Exit Sub
Else
wdInputName = .SelectedItems(1)
End If
End With
'Set oWord = New Word.Application
Set oWdoc = oWord.Documents.Open(wdInputName)
' Start mail merge
'------------------------------------------------
With oWdoc.MailMerge
.MainDocumentType = wdFormLetters
.OpenDataSource _
Name:=CurrentProject.FullName, _
AddToRecentFiles:=False, _
LinkToSource:=True, _
Connection:="TABLE tblMailMergeTMP", _
SQLStatement:="SELECT * FROM [tblMailMergeTMP]"
.Destination = wdSendToEmail
.MailAsAttachment = False
.MailFormat = wdMailFormatHTML
.MailAddressFieldName = "UserID"
.MailSubject = "Joining Instructions for: " & cbxCourse.Column(0)
.Execute Pause:=False
End With
' Hide Word During Merge
'------------------------------------------------
oWord.Visible = False
' Quit Word to Save Memory
'------------------------------------------------
oWord.Quit savechanges:=False
' Clean up memory
'------------------------------------------------
Set oWord = Nothing
Set oWdoc = Nothing