Move Outlook messages to the archive by pressing a hot key

    After I traded The Bat! on Outlook, I really lacked one important functionality. In the old man, it was possible to configure so that by pressing Shift + Del the selected group of letters would be transferred to any other folder instead of Deleted Items. In Outlook, in order to keep Inbox clean, you have to suffer drag and drop. But, fortunately, it turned out the hotkey can be configured for Outlook.

    To do this, you will need:
    1. Decide on the folder where to transfer,
    2. Create a macro (code below) and enter the name of the folder in it,
    3. Place a new button on the toolbar,
    4. Assign a hotkey to the button.

    This is not so difficult and takes only five to ten minutes if you follow the instructions below.

    First, open the macro creation window in Outlook (by pressing Alt-F8), and for the macro name, for example, enter MoveSelectedMessagesToFolder, and then click Create.



    Next, a scary and incomprehensible window for editing Microsoft Visual Basic macros with a blank for a new script will appear:

    Sub MoveSelectedMessagesToFolder ()
    End sub

    However, do not be embarrassed, you won’t have to write a single line of code (except for fixing one little thing). Just replace all the code with the one below:

    Option Explicit
    Sub MoveSelectedMessagesToFolder ()
    On Error Resume Next
    Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder
    Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem
    Set objNS = Application.GetNamespace ("MAPI")
    Set objInbox = objNS.GetDefaultFolder (olFolderInbox)
    Set objFolder = objInbox.Folders (" Archive ")
    If objFolder Is Nothing Then
        MsgBox "This folder doesn't exist!", VbOKOnly + vbExclamation, "INVALID FOLDER"
    End if
    If Application.ActiveExplorer.Selection.Count = 0 Then
        'Require that this procedure be called only when a message is selected
        Exit sub
    End if
    For Each objItem In Application.ActiveExplorer.Selection
        If objFolder.DefaultItemType = olMailItem Then
            If objItem.Class = olMail Then
                objItem.Move objFolder
            End if
        End if
    Next
    Set objItem = Nothing
    Set objFolder = Nothing
    Set objInbox = Nothing
    Set objNS = Nothing
    End sub
    

    Please note that the name of the folder in which letters will be moved I have underlined. In my case, it is called "Archive", if you want to specify any other. This must be one of the existing inbox folders.

    You can check if the macro works by running it with the green play button at the top. If everything goes ok, then the letter that is currently selected in the Inbox will go to the desired folder.

    After you are done with the script, save it (Ctrl + S) and close the script editor window.

    Now we will take out a new button in the toolbar. To do this, right-click on the toolbar and select the item Settings ... (Customize ...). The following window will appear:



    In the Macros category we find our only macro and drag it somewhere to the toolbar area (but not in the menu). Without closing the Settings window (if closed, open it again), right-click on the button that appears on the toolbar and select the appropriate icon and name for it, for example, "Move & to archive". For the button to have a hot key, you need to put the & icon in front of any letter in the name that you have assigned. Then you can call the macro with the Alt + letter key combination (Alt + in our case). Now you can close the settings window and check if the hotkey works.

    It may happen that your keyboard shortcut is already taken. You will find this when you try to call your macro, and another button on the toolbar is called. In this case, call up the settings window again and change the hot key for one of the conflicting buttons.

    Voila. I hope you have succeeded. If something did not work out, I will gladly help in the comments.

    Also popular now: