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
.DataSource.Close
End With
Any hints / suggestions as to why Word is keeping the datasource file locked would be much appreciated.