Action object in Outlook Add-in with Visual Basic for Application code

Action object in Outlook Add-in with Visual Basic for Application code

Action

Refers to a specific action in outlook. Action object is very useful to execute various actions in Outlook like, Voting response, reply to a mail item etc. Action object provides two methods, Execute, and Delete. Let’s put some code to gather to perform actions.

Code example

Public Sub PerformActionExample()

    'Outlook application object declaration
    Dim oApp As Outlook.Application
    
    'bind current outlook instance
    Set oApp = GetObject("", "Outlook.Application")
    
    'Get current email
    Dim GetCurrentItem As MailItem
    
    Select Case TypeName(oApp.ActiveWindow)
        Case "Explorer"
            Set GetCurrentItem = oApp.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set GetCurrentItem = oApp.ActiveInspector.CurrentItem
    End Select
    
    'Verify selected item is a valid mail
    If GetCurrentItem.Class = olMail Then
    'Perform action
        GetCurrentItem.Actions("Reply").ReplyStyle = olIncludeOriginalText
        GetCurrentItem.Actions("Reply").Execute
    End If
    
    'Cleanup
    If Not GetCurrentItem Is Nothing Then
        Set GetCurrentItem = Nothing
    End If
    If Not oApp Is Nothing Then
        Set oApp = nohting
    End If
End Sub

Next >> Create or Run Rules in Outlook using VBA code example

Leave a Reply

Your email address will not be published. Required fields are marked *