Had some trouble with Word automation. Sorted it, in the process thought I
would try late binding. Some people reccomend it. So this:
*************** *************** *************** ************
Public Sub MailMerge(strQu ery As String, strTemplate As String)
snip
Dim doc As Word.Document
Dim wrdApp As Word.Applicatio n
snip
Set wrdApp = New Word.Applicatio n
Set doc = wrdApp.Document s.Add(strPath & strTemplate)
With doc.MailMerge
..Destination = wdSendToNewDocu ment
..SuppressBlank Lines = True
With .DataSource
..FirstRecord = wdDefaultFirstR ecord
..LastRecord = wdDefaultLastRe cord
End With
If .State = wdMainAndDataSo urce Then .Execute
End With
wrdApp.Visible = True
snip
End Sub
*************** *************** *************** ************
works, with a reference to the Word olb
If i change it to:
*************** *************** *************** ************
Public Sub MailMerge(strQu ery As String, strTemplate As String)
snip
Dim doc As object
Dim wrdApp as object
snip
Set wrdApp = CreateObject("W ord.Application ")
Set doc = wrdApp.Document s.Add(strPath & strTemplate)
With doc.MailMerge
..Destination = wdSendToNewDocu ment
..SuppressBlank Lines = True
With .DataSource
..FirstRecord = wdDefaultFirstR ecord
..LastRecord = wdDefaultLastRe cord
End With
If .State = wdMainAndDataSo urce Then .Execute
End With
wrdApp.Visible = True
snip
End Sub
*************** *************** *************** ************
it halts on
..Destination = wdSendToNewDocu ment
with wdSendToNewDocu ment highlighted and 'unknown variable'
Any ideas?
TIA, Mike MacSween
would try late binding. Some people reccomend it. So this:
*************** *************** *************** ************
Public Sub MailMerge(strQu ery As String, strTemplate As String)
snip
Dim doc As Word.Document
Dim wrdApp As Word.Applicatio n
snip
Set wrdApp = New Word.Applicatio n
Set doc = wrdApp.Document s.Add(strPath & strTemplate)
With doc.MailMerge
..Destination = wdSendToNewDocu ment
..SuppressBlank Lines = True
With .DataSource
..FirstRecord = wdDefaultFirstR ecord
..LastRecord = wdDefaultLastRe cord
End With
If .State = wdMainAndDataSo urce Then .Execute
End With
wrdApp.Visible = True
snip
End Sub
*************** *************** *************** ************
works, with a reference to the Word olb
If i change it to:
*************** *************** *************** ************
Public Sub MailMerge(strQu ery As String, strTemplate As String)
snip
Dim doc As object
Dim wrdApp as object
snip
Set wrdApp = CreateObject("W ord.Application ")
Set doc = wrdApp.Document s.Add(strPath & strTemplate)
With doc.MailMerge
..Destination = wdSendToNewDocu ment
..SuppressBlank Lines = True
With .DataSource
..FirstRecord = wdDefaultFirstR ecord
..LastRecord = wdDefaultLastRe cord
End With
If .State = wdMainAndDataSo urce Then .Execute
End With
wrdApp.Visible = True
snip
End Sub
*************** *************** *************** ************
it halts on
..Destination = wdSendToNewDocu ment
with wdSendToNewDocu ment highlighted and 'unknown variable'
Any ideas?
TIA, Mike MacSween
Comment