Share via


Application.MailMergeWizardStateChange Event

Word Developer Reference

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

Syntax

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

expression   A variable that represents an Application object that has been declared with events in a class module. For information about using events with the Application object, see Using Events with the Application Object.

Parameters

Name Required/Optional Data Type Description
Doc Required Document The mail merge main document.
FromState Required Long The Mail Merge Wizard step from which a user is moving.
ToState Required Long The Mail Merge Wizard step to which a user is moving.
Handled Required Boolean 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.

Visual Basic for Applications
  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

See Also