O
oscarba
Sorry for my english.
When I execute this code, MailMergeBeforeMerge Event isn´t executed
but if I merge document directly in word MailMergeBeforeMerge Event i
recognize. Why????????
ThisDocument:
------------
Dim X As New Eventos
Sub Register_Eventos_Handler()
Set X.App = Word.Application
Combinar ThisDocument
End Sub
Sub Combinar(Doc As Document)
If ThisDocument.MailMerge.State = wdMainAndDataSource Then
With Doc.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
End If
End Sub
Eventos:
--------
Public WithEvents App As Application
Private Sub App_MailMergeBeforeMerge(ByVal Doc As Document, ByVal _
StartRecord As Long, ByVal EndRecord As Long, Cancel As Boolean)
Dim intVBAnswer As Integer
'Request whether the user wants to continue with the merge
intVBAnswer = MsgBox("Mail Merge for " & _
Doc.Name & " is now starting. " & _
"Do you want to continue?", vbYesNo, "MailMergeBeforeMerg
Event")
'If users response to question is No, cancel the merge process
'and deliver a message to the user stating the merge is cancelled
If intVBAnswer = vbNo Then
Cancel = True
MsgBox "You have cancelled mail merge for " & _
Doc.Name & "."
End If
End Su
When I execute this code, MailMergeBeforeMerge Event isn´t executed
but if I merge document directly in word MailMergeBeforeMerge Event i
recognize. Why????????
ThisDocument:
------------
Dim X As New Eventos
Sub Register_Eventos_Handler()
Set X.App = Word.Application
Combinar ThisDocument
End Sub
Sub Combinar(Doc As Document)
If ThisDocument.MailMerge.State = wdMainAndDataSource Then
With Doc.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
End If
End Sub
Eventos:
--------
Public WithEvents App As Application
Private Sub App_MailMergeBeforeMerge(ByVal Doc As Document, ByVal _
StartRecord As Long, ByVal EndRecord As Long, Cancel As Boolean)
Dim intVBAnswer As Integer
'Request whether the user wants to continue with the merge
intVBAnswer = MsgBox("Mail Merge for " & _
Doc.Name & " is now starting. " & _
"Do you want to continue?", vbYesNo, "MailMergeBeforeMerg
Event")
'If users response to question is No, cancel the merge process
'and deliver a message to the user stating the merge is cancelled
If intVBAnswer = vbNo Then
Cancel = True
MsgBox "You have cancelled mail merge for " & _
Doc.Name & "."
End If
End Su