Microsoft Office Tutorials and References
In Depth Information
Mail Merge: Merging with a Chart
Option explicit¶
' * * * * *¶
Public x As New clsMergeEvents¶
Public BeforeMergeExecuted As Boolean¶
Public CancelMerge As Boolean¶
Public recordIndex As Long¶
Const ChartDataDoc As String = "MailMergePieChartData.doc"¶
' * * * * *¶
Sub MergeWithChart()¶
'Preset the global variables¶
BeforeMergeExecuted = False¶
CancelMerge = False¶
recordIndex = 1¶
'The events in the class module¶
'clsMergeEvents will be enabled¶
ActivateEvents¶
'As each record is merged¶
'the MailMergeBeforeMerge¶
'event will be called¶
ActiveDocument.MailMerge.Execute¶
'Turn the events off so that they¶
'only execute for this document¶
DeactivateEvents¶
End Sub¶
' * * * * *¶
Sub ActivateEvents()¶
Set x.WdApp = Word.Application¶
End Sub¶
' * * * * *¶
Sub DeactivateEvents()¶
Set x.WdApp = Nothing¶
End Sub¶
' * * * * *¶
Function OpenChartDataFile(LocalPath As String) _¶
As Word.Document¶
'Variable declarations¶
Dim FilePath As String¶
'Combine the path where the main merge doc¶
'is stored plus the specified name of the¶
'document containing the data for the chart¶
FilePath = LocalPath & "\" & ChartDataDoc¶
'Make sure the data file exists¶
'before trying to open it¶
If Dir(FilePath) <> "" Then¶
Set OpenChartDataFile = Documents.Open( _¶
FileName:=FilePath, _¶
ReadOnly:=True, _¶
AddToRecentFiles:=False, _¶
Visible:=False)¶
End If¶
End Function¶
Wrd
Search JabSto ::




Custom Search