Recalling messages

In Recalling Sent Messages, Diane Poremsky covers the feature in Outlook that lets you recall messages. It's not a great feature and I've never used it, but if you ever did need to, it is possible to do so programmatically.

Personally, I make sure that the message I want to send is correct before sending. If I do need to follow up, I send another message. The automated recall message just makes you look bad.

Code to Recall a Sent Message

The following code is simple: it simulates the action of going to the toolbar and going to Actions » Recall This Message for a given item.

recall this message

Select an email in your Sent Items folder that you want to recall and run this code:

Sub SendRecall()

  Dim obj As Object
  Dim msg As Outlook.MailItem
  Dim insp As Outlook.Inspector

  ' get selected item
  ' assume it's an email in Sent Items folder
  Set obj = ActiveExplorer.Selection.Item(1)

  If TypeName(obj) = "MailItem" Then ' it's an email
    Set msg = obj
    Set insp = msg.GetInspector
    ' execute the command button for "Recall this message"
    With insp
      .Display
      .CommandBars.FindControl(, 2511).Execute
      .Close olDiscard
    End With
  End If
End Sub

I know this works in Outlook 2003, not sure if it will work in the newer versions. If you try it in another version and it works, please leave a comment.

You may want to get more sophisticated with this. For example, I was lazy and didn't bother to check if an item was selected or open. To do that, use this function:

Function GetCurrentItem() As Object
  Select Case True
  Case IsExplorer(Application.ActiveWindow)
    Set GetCurrentItem = ActiveExplorer.Selection.Item(1)
  Case IsInspector(Application.ActiveWindow)
    Set GetCurrentItem = ActiveInspector.CurrentItem
  End Select

End Function

You may also want to check that the current folder is actually the Sent Items folder. You can do this at least two ways that I know of.

  1. Do a superficial check of the folder name:
  2. ActiveExplorer.CurrentFolder.Name

    If the folder name is Sent Items, you should be good.

  3. After checking the name of the folder using the code above, check if the folder is one of the default folders
  4. Use the FolderIsDefault function. You would pass the folder object to this function — in this case it would be obj.Parent.

So our updated code would look like this:

Sub SendRecall()

  Dim obj As Object
  Dim msg As Outlook.MailItem
  Dim insp As Outlook.Inspector

  ' get currently selected or open item
  Set obj = GetCurrentItem

  If TypeName(obj) = "MailItem" Then ' it's an email
    If ActiveExplorer.CurrentFolder.Name = "Sent Items" Then 
      If FolderIsDefault(obj.Parent) Then 
        ' we are in the default Sent Items folder
        Set msg = obj
        Set insp = msg.GetInspector
        ' execute the command button for "Recall this message"
        With insp
          .Display
          .CommandBars.FindControl(, 2511).Execute
          .Close olDiscard
        End With
      End If
    End If
  End If
End Sub
About JP

I'm just an average guy who writes VBA code for a living. This is my personal blog. Excel and Outlook are my thing, with a sprinkle of Access and Word here and there. Follow this space to learn more about VBA. Keep Reading »


Related Articles:


Share This Article:

Share and bookmark this articledelicious buttonfacebook buttonlinkedin buttonstumbleupon buttontwitter button

This article is closed to any future comments.
Random Data Generator