Hi,
I found a problem when merging information from the workbook currently
running the code to mail merge and the work around was to create a back up
of the file first and use that to link in the mail merge.
Sub print_Click()
Dim FName As String
Dim appWD As Object ' Word.Application
Dim UserN As String
Dim DesktopPath As String
On Error Resume Next
Application.StatusBar = "Starting mail merge ..."
'create a backup of the current workbook to use as the mail merge file
Application.DisplayAlerts = False
ThisWorkbook.SaveCopyAs ThisWorkbook.Path & "\addresses-backup.xls"
Application.DisplayAlerts = True
FName = Dir(ThisWorkbook.Path & "\addresses-backup.xls")
If appWD Is Nothing Then
Set appWD = CreateObject("Word.Application") ' New Word.Application
End If
appWD.Documents.Open Filename:=ThisWorkbook.Path & "\label
merge-auto.doc"
With appWD.ActiveDocument.MailMerge
.OpenDataSource Name:=ThisWorkbook.Path & "\" & FName,
sqlstatement:="SELECT * FROM [print list$]"
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.Execute Pause:=False
End With
Application.StatusBar = "Now creating document for " & Left(FName,
Len(FName) - 4)
appWD.ActiveDocument.SaveAs (ThisWorkbook.Path & "\merged" &
Format(Date, "dd-mm-yyyy") & "-week" & _
Worksheets("label order").Range("Q4").Value),
FileFormat:=wdFormatDocument
appWD.ActiveDocument.Close
appWD.Documents("label merge-auto.doc").Close savechanges:=False
appWD.Quit
Set appWD = Nothing
'remove backup file
Kill ThisWorkbook.Path & "\addresses-backup.xls"
Application.StatusBar = False
End Sub
The code is lifted from mine and it was adapted for my use from an article
online. Please use as required..
Regards
Anthony