CustomAction Event

Microsoft Outlook Visual Basic

Occurs when a custom action of a Microsoft Outlook item executes. The Action object and the newly created item resulting from the custom action are passed to the event.

Sub object_CustomAction(ByVal Action As Object, ByVal Response As Object, Cancel As Boolean)

object    An expression that evaluates to one of the objects in the Applies To list. In VBScript, use the word Item.

Action       Required. The Action object.

Response    Required. The newly created item resulting from the custom action.

Cancel Optional (not used in VBScript). False when the event occurs. If the event procedure sets this argument to True, the custom action is not completed.

Remarks

In Microsoft Visual Basic Scripting Edition (VBScript), if you set the return value of this function to False, the custom action operation is not completed.

Example

This Visual Basic for Applications (VBA) example uses the CustomAction event to set the Subject property on the response item. Execute the AddAction procedure before executing the Initialize_Handler to create an item with a custom event called 'Link Original'.

Public WithEvents myItem As Outlook.MailItem
Dim myOlApp As New Outlook.Application
    
Sub AddAction()
 Dim myAction As Outlook.Action
 Set myItem = myOlApp.CreateItem(olMailItem)
 Set myAction = myItem.Actions.Add
 myAction.Name = "Link Original"
 myAction.ShowOn = olMenuAndToolbar
 myAction.ReplyStyle = olLinkOriginalItem
 myItem.To = "Dan Wilson"
 myItem.Subject = "Before"
 myItem.Send
End Sub

Sub Initialize_Handler()
 Set myItem = myOlApp.ActiveInspector.CurrentItem
End Sub

Private Sub myItem_CustomAction(ByVal Action As Object, ByVal Response As Object, Cancel As Boolean)
 Select Case Action.Name
        Case "Link Original"
            Response.Subject = "Changed by VB Script"
        Case Else
  End Select
End Sub