Hi,
Im having a little problem with a mailmerge I'm controling from Excel. To make it a little easier the users I'm doing this for are on a different OS, different version of Office, in a different office 250 miles away, and know even less about VBA than I do! Anyhoo here's my code- this is in a module in Excel
It works fine on my office machine (XP- office 2003) but when I send it to another office who use NT and Office 2000 it fails to produce the new document- stepping thru the code is pretty uneventful- no crashes or errors just that as I get to the last step of the With wdApp.ActiveDocument.MailMerge group my XP machine produces FormLetters1.doc as my merged document and the NT/2000 version just sits there defiantly not producing a new document! The next part then closes the merging document as it should.
I had issues with Early/Late binding, but I think I'm now fully late bound- I've got rid of all the default references and checked that the 2000 version isn't expecting word 11.0 object library- the code runs thru without erroring, just won't merge. The datafile is already linked to the word documents and when they open them manually the merge fields populate with the data so I don't think that is the problem- but on the basis that I can't see to be sure if there is a VBA way of attaching the datafile to the letter that might be worth doing just to be sure.
Can anyone see where I am going wrong, or give me any clues as to what the issue might be??
Thanks for your help
GaryB
Im having a little problem with a mailmerge I'm controling from Excel. To make it a little easier the users I'm doing this for are on a different OS, different version of Office, in a different office 250 miles away, and know even less about VBA than I do! Anyhoo here's my code- this is in a module in Excel
Code:
Sub CreateLetter()
Dim wdApp As Object
Set wdApp = CreateObject("Word.Application")
Dim LtrType As Integer
Dim myLetter As String
LtrType = Range("FT1Stat2")
If LtrType = 1 Then
myLetter = "h:\ftfaq.doc"
ElseIf LtrType = 2 Then
myLetter = "h:\statfaq.doc"
End If
On Error Resume Next
Set wdApp = GetObject("word.application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
wdApp.Visible = True
wdApp.Documents.Open myLetter
With wdApp.ActiveDocument.MailMerge
.Destination = 0 '0=wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = 1 'wdDefaultFirstRecord
.LastRecord = 1 'wdDefaultLastRecord
End With
.Execute Pause:=False
End With
If LtrType = 1 Then
wdApp.Windows("ftfaq.doc").Close False
ElseIf LtrType = 2 Then
wdApp.Windows("statfaq.doc").Close False
End If
wdApp.Activate
End Sub
It works fine on my office machine (XP- office 2003) but when I send it to another office who use NT and Office 2000 it fails to produce the new document- stepping thru the code is pretty uneventful- no crashes or errors just that as I get to the last step of the With wdApp.ActiveDocument.MailMerge group my XP machine produces FormLetters1.doc as my merged document and the NT/2000 version just sits there defiantly not producing a new document! The next part then closes the merging document as it should.
I had issues with Early/Late binding, but I think I'm now fully late bound- I've got rid of all the default references and checked that the 2000 version isn't expecting word 11.0 object library- the code runs thru without erroring, just won't merge. The datafile is already linked to the word documents and when they open them manually the merge fields populate with the data so I don't think that is the problem- but on the basis that I can't see to be sure if there is a VBA way of attaching the datafile to the letter that might be worth doing just to be sure.
Can anyone see where I am going wrong, or give me any clues as to what the issue might be??
Thanks for your help
GaryB
Last edited: