Execute Method (Dialog, KeyBinding, and MailMerge Objects) Example

The following example enables the Keep with next check box on the Line and Page Breaks tab in the Paragraph dialog box.

With Dialogs(wdDialogFormatParagraph)
    .KeepWithNext = 1
    .Execute
End With

This example assigns the CTRL+SHIFT+C key combination to the FileClose command and then executes the key combination (the document is closed).

CustomizationContext = ActiveDocument.AttachedTemplate
Keybindings.Add KeyCode:=BuildKeyCode(wdKeyControl, _
    wdKeyShift, wdKeyC), KeyCategory:=wdKeyCategoryCommand, _
    Command:="FileClose"
FindKey(BuildKeyCode(wdKeyControl, wdKeyShift, wdKeyC)).Execute

This example executes a mail merge if the active document is a main document with an attached data source.

Set myMerge = ActiveDocument.MailMerge
If myMerge.State = wdMainAndDataSource Then MyMerge.Execute