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
Cindy M -WordMVP- - 27 Dec 2003 14:47 GMT
Hi Oscarba,
> When I execute this code, MailMergeBeforeMerge Event isn´t executed,
> but if I merge document directly in word MailMergeBeforeMerge Event is
> recognize. Why??
I had hoped this problem had been fixed in Word 2003... <sigh>
MailMergeBeforeMerge only fires if mail merge is executed from the "Mail
merge wizard" taskpane. But not from the toolbar, or from VBA code.
What I've done, on occasion, is to use a global boolean variable to
track when the the code I want to do "before merge" has been executed.
MailmergeBeforeRecordMerge sets the variable, so that the BeforeMerge
code executes only on the first record. And AfterMerge then resets it
for a possible second merge is run in the same scope.
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word
This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)
oscarba - 29 Dec 2003 10:54 GMT
Cindy,
thanks for your help.
------------------------------------------------