Microsoft Word - Datasource not being released after an automated mail merge

Asked By Andrew Lockwood on 06-May-12 06:17 PM
I am pulling my hair out over this one!

I have written a macro which merges a Word template with a .csv file created in another program.  The merge works fine, but the datasource file remains locked by Word, so I cannot create a new .csv file until I have closed all open documents in Word (not just the one I have created by the merge).  This is a major headache when wanting to create multiple documents in succession.

With ActiveDocument.MailMerge
            .OpenDataSource _
                Name:="d:\documents and settings\shared\word invoice.csv"
            .Destination = wdSendToNewDocument
            .SuppressBlankLines = True
            With .DataSource
                .FirstRecord = wdDefaultFirstRecord
                .LastRecord = wdDefaultLastRecord
            End With
            .Execute Pause:=False
End With

Any hints / suggestions as to why Word is keeping the datasource file locked would be much appreciated.

[)ia6l0 iii replied to Andrew Lockwood on 07-May-12 12:38 PM
How about activedocument.close after the mail merge?

With ActiveDocument.MailMerge

End With 

Somesh Yadav replied to Andrew Lockwood on 08-May-12 02:32 AM
try this,