Microsoft Office Tutorials and References
In Depth Information
Mail Merge: Merging with a Chart
Option explicit¶
' * * * * *¶
Public WithEvents WdApp As Word.Application¶
Private DataDoc As Word.Document¶
Const BookmarkName As String = "PieChart"¶
Const sMergeMessage As String = "The merge process can take some time."
& _¶
vbCr & vbCr & "Word may pause and seem to hang while the charts
update." _¶
& vbCr & vbCr & "Please do NOT try to work " & _¶
"in Word until the 'finish' message has been displayed!"¶
Private Sub WdApp_MailMergeAfterMerge(ByVal Doc As Document, _¶
ByVal DocResult As Document)¶
DataDoc.Close SaveChanges:=wdDoNotSaveChanges¶
Set DataDoc = Nothing¶
MsgBox "Merge process has finished!"¶
'Display the merge result document¶
If Not DocResult Is Nothing Then¶
DocResult.Activate¶
End If¶
End Sub¶
' * * * * *¶
Private Sub WdApp_MailMergeBeforeRecordMerge( _¶
ByVal Doc As Document, Cancel As Boolean)¶
'Variable declaration¶
Dim rngChart As Word.Range¶
' Dim rngControl As Word.Range¶
' Dim EmployeeName As String¶
Debug.Print Doc.Characters.Count, Asc(Doc.Characters.Last)¶
'If something is wrong, don't continue¶
'processing each record¶
If CancelMerge = True Then¶
Debug.Print "Cancelled. Record: " & CStr(recordIndex)¶
Cancel = True¶
Exit Sub¶
End If¶
'The file containing the data for the merge¶
'should only be opened once. Therefore,¶
'track when the merge has started¶
If BeforeMergeExecuted = False Then¶
BeforeMergeExecuted = True¶
MsgBox sMergeMessage, vbCritical + vbOKOnly¶
Set DataDoc = OpenChartDataFile(Doc.Path)¶
End If¶
If DataDoc Is Nothing Then¶
MsgBox "The data document could not be opened."¶
CancelMerge = True¶
Cancel = True¶
Exit Sub¶
End If¶
'If there is no target for the chart, then¶
Wrd
Search JabSto ::




Custom Search