Home > Mobile >  Trying to recall a sent message in Outlook
Trying to recall a sent message in Outlook

Time:02-02

I am trying to get a vba in outlook to recall the message currently selected.

the code I found is.

Option Explicit
Sub Recall()
  Dim SendItem As Object
  Dim olItem As Outlook.MailItem
  Dim olInsp As Outlook.Inspector

  '// Selected item in Sent Items folder
  Set SendItem = ActiveExplorer.Selection.Item(1)

  If TypeName(SendItem) = "MailItem" Then
    Set olItem = SendItem
    Set olInsp = olItem.GetInspector
    '// Execute Recall command button
    With olInsp
      .Display
      .CommandBars.FindControl(, 2511).Execute
      .Close olDiscard
    End With
  End If
End Sub

I am getting an error on the line of .CommandBars.FindControl(, 2511).Execute. How should the code be modified?

CodePudding user response:

Command bars were deprecated and not used any longer. The Fluent UI (aka Ribbon UI) is used, so any old code may not work any longer. Only some methods are supported such as ExecuteMso which allows to execute buult-in ribbon controls. The CommandBars.ExecuteMso methods accepts a string which represents the identifier for the control. You need to pass the ribbon idMso value of the control instead.

CommandBars.ExecuteMso("RecallThisMessage")

But you need to make sure that such controls are available in Outlook. Message recall is available after you click Send and is available only if both you and the recipient have a Microsoft 365 or Microsoft Exchange email account in the same organization. So, for example, a message sent to or from a Hotmail, Gmail, or live.com account can't be recalled.

  • Related