Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vba

outlook

I have an Outlook macro that marks-as-read and moves all messages in a conversation into another folder. I assigned the macro to a button called "Archive". However, I cannot "undo" that action. If I

  1. delete a message
  2. archive a message
  3. undo

I end up un-deleting the message. I thought I would un-move the message. If I move a message by dragging and dropping it into another folder, undo works the way I expect. Here's the macro, does anyone know why this wouldn't 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 have to code in undo support?

like image 563
Anthony Mastrean Avatar asked Oct 11 '22 09:10

Anthony Mastrean


1 Answers

Unfortunately Outlook's undo functionality only operates on the user's actions, not on programmatic actions. Excel allows this via the Application.OnUndo hook, but this isn't implemented in Outlook.

Maybe a reasonable alternative would be to create an 'Undo last archive' button; as long as you store the last archive action somewhere you can get to it, when the user clicks your 'undo' button then your macro manually moves the message back and marks it as unread (if it was originally that way).

like image 162
Geoff Avatar answered Oct 15 '22 09:10

Geoff