Why does undo not work with an Outlook macro that marks as read and moves mail items?

I have an Outlook macro that marks as read and moves all messages in the thread to another folder. I assigned a macro to the Archive button. However, I cannot β€œundo” this action. If I

  • delete message
  • Archive message
  • Cancel

As a result, I delete the message. I thought I would not translate the message. If I move the message by dragging it to another folder, the cancellation works as I expect. Here's a macro, does anyone know why this does not support undo?

Sub ArchiveConversation() Set ArchiveFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders("Archive") Set Conversations = ActiveExplorer.Selection.GetSelection(Outlook.OlSelectionContents.olConversationHeaders) For Each Header In Conversations Set Items = Header.GetItems() For i = 1 To Items.Count Items(i).UnRead = False Items(i).Move ArchiveFolder Next i Next Header End Sub 

Or do I need to code support for cancellation?

+4
source share
1 answer

Unfortunately, the undo function of Outlook only works on user actions, not programmatic actions. Excel allows this using Application.OnUndo , but it is not implemented in Outlook.

Perhaps a sensible alternative would be to create a β€œUndo Last Archive" button; while you save the last action in the archive somewhere, you can get to it when the user clicks the cancel button, then your macro manually moves the message back and marks it as unread (if it was originally this way).

+3
source

All Articles