Outlook 2016 Mac – Are Macros Available?

applescriptms office

In Outlook on Windows I have a VBA script that moves one or more messages from Inbox to a folder, attached to a keyboard shortcut that I use to very quickly move hundreds of emails to where I want them every day.

Is there any feature like that in Outlook on Mac? I'm not sure how to phrase the question, I don't want to be too narrow by asking "Is there VBA and Macros in Outlook on Mac" when obviously there is not, but is there some other way to approach this problem, automating things and assigning keyboard shortcuts to personalized tasks?

Edit: One comment mentioned Applescript. (I'm a newbie to Mac). I then found this article on enabling the Applescript icon and this article on using Applescript to create a Task from a Message. That's not exactly what I want but it's a HUGE step forward. I will now study Applescript and Outlook's use of it and if I get anywhere, will answer my own question.

Best Answer

Here is a way in Outlook 2016 on Mac to do the equivalent of Windows "Write a VB script and assign it to a key". Thanks to those who pointed me in the right direction. On Mac this is done with Applescript, Automator, and Keyboard Shortcuts. I'm including the Applescript here that moves selected Outlook emails to an archive folder. Also shown below for reference is the original VBA I was trying to emulate on Mac.

Step 1 – Write Applescript to move selected Outlook item to Archive

  • Press Command-Tab to launch Spotlight Search, type “Script Editor” to launch it.
  • Optional: Install a shortcut to the script editor in the Apple menu as follows. You have to be in the script editor first, then in the menu at the top choose Script Editor->Preferences. Then in preferences choose General, and check (enable) “Show Script menu in menu bar” and also “Show Computer scripts”.
  • Start with the following script. Run it, test it, play with it. Look elsewhere for help on changing this to do exactly what you want. This script moves the currently selected email(s) to a folder named “IZ – Archive”. Change the folder name to suit yourself. There’s lots of room for improvement here. I’d like to solve the Reminders problem.

    tell application "Microsoft Outlook"
        -- get the currently selected message or messages
        -- NOTE in this version it fails if the Outlook Reminder window is open, even if you select a message in the main window.
        set selectedMessages to current messages
    
        -- if there are no messages selected, warn the user and then quit
        if selectedMessages is {} then
            display dialog "Please select a message first and then run this script." with icon 1
            return
        end if
    
        set aMessage to item 1 of selectedMessages
        set emailAcct to account of aMessage
        set inBoxFolder to folder "Inbox" of emailAcct
        set ArchiveFolder to folder "IZ - Archive" of inbox
    
        repeat with theMessage in selectedMessages
            move theMessage to IZArchiveFolder
        end repeat
    end tell
    

Step 2 – Assign the Applescript to a Service using Automator

  • Press Command-Tab to launch Spotlight Search, from there launch Automator
  • In Automator, choose a type for your document, choose “Service”. You will create a service from your script.
  • At the top of the service, set the two settings to: Service receives no input in any application From the left panel, choose Library, then in the second panel from the long list find “Run Applescript”, and drag that into the main service window.
  • Copy and paste your Applescript replacing (* Your script goes here *)

  • Save the service, giving it a name like MoveSelectedOutlookMailToArchive. It’s not obvious how to “Save As” in Automator. Play around with the “File” menu at the top of the screen and do some googling.

  • The service will be saved under ~/Library/Services/yourservicename

Step 3 – Assign the Service to a Key

  • Go to Keyboard Shortcuts either from Outlook Menu->Outlook->Services->Services Preferences or from System Preferences->Keyboard->Shortcuts->Services
  • In the Keyboard Shortcuts editor choose “Services” on the left, then go to the bottom under the “General” section where you will find your new service.
  • Click on that, and assign the keyboard shortcut you would like.

============

For reference and comparison here is the original VBA script I was trying to emulate on Mac. As you can see, the Applescript is more concise and intuitive, on the other hand the mechanism to assign it to a key (not shown here) is WAY easier on PC.

'Outlook VB Macro to move selected mail item(s) to a target folder
Sub MoveToIZArchive()
On Error Resume Next

Dim ns As Outlook.NameSpace
Dim moveToFolder As Outlook.MAPIFolder
Dim objItem As Outlook.MailItem

Set ns = Application.GetNamespace("MAPI")

'Define path to the target folder
Set moveToFolder = ns.GetDefaultFolder(olFolderInbox).Folders("IZ - Archive")

If Application.ActiveExplorer.Selection.Count = 0 Then
   MsgBox ("No item selected")
   Exit Sub
End If

If moveToFolder Is Nothing Then
   MsgBox "Target folder not found!", vbOKOnly + vbExclamation, "Move Macro Error"
End If

For Each objItem In Application.ActiveExplorer.Selection
   If moveToFolder.DefaultItemType = olMailItem Then
      If objItem.Class = olMail Then
         'objItem.UnRead = False
         objItem.Move moveToFolder
      End If
  End If
Next

Set objItem = Nothing
Set moveToFolder = Nothing
Set ns = Nothing

End Sub