MailMergeWizardStateChange Event

Microsoft Word Visual Basic

Show All

MailMergeWizardStateChange Event

       

Occurs when a user changes from a specified step to a specified step in the Mail Merge Wizard.

Private Sub object_MailMergeWizardStateChange(ByVal Doc As Document, FromState As Long, ToState As Long, Handled As Boolean)

object  An object of type Application declared with events in a class module. For information about using events with the Application object, see Using Events with the Application Object.

Doc  The mail merge main document.

FromState  The Mail Merge Wizard step from which a user is moving.

ToState  The Mail Merge Wizard step to which a user is moving.

Handled  True moves the user to the next step. False for the user to remain at the current step.

Example

This example displays a message when a user moves from step three of the Mail Merge Wizard to step four. Based on the answer to the message, the user will either move to step four or remain at step three. This example assumes that you have declared an application variable called MailMergeApp in your general declarations and have set the variable equal to the Word Application object.

Private Sub MailMergeApp_MailMergeWizardStateChange(ByVal Doc As Document, _
    FromState As Long, ToState As Long, Handled As Boolean)

    Dim intVBAnswer As Integer
    FromState = 3
    ToState = 4

    'Display a message when moving from step three to step four
    intVBAnswer = MsgBox("Have you selected all of your recipients?", _
        vbYesNo, "Wizard State Event!")

    If intVBAnswer = vbYes Then
        'Continue on to step four
        Handled = True
    Else
        'Return to step three
        MsgBox "Please select all recipients to whom " & _
            "you want to send this letter."
        Handled = False
    End If

End Sub