useful outlook macros

Smart Email Solutions: Useful Outlook Macros

5.7 min read|Last Updated: November 30th, 2023|Categories: excel|
table of content

When it comes to transforming businesses and implementing digital solutions, repetitive tasks come to mind. Business owners can take small steps to tackle the problem because even small actions can have a noticeable impact in the long run. 

Macros are there to help you perform repetitive tasks without having to go through all the steps over and over again. In other words, it’s a time-saver function in Office programs, such as Excel and Outlook. 

How to use Macros in Outlook?

First of all, you need to know where to find macros and how to use them on Outlook. Macros are available under the Developer tab, which is not preloaded on Outlook. So, you need to set it up. The process is straightforward. Follow these steps: 

  1. Hit the mouse’s right-click button anywhere on the Outlook Ribbon. 
  2. A menu will open. Click on the Customize Ribbon
  3. There are different options on the window that opens. The Developer is an option under the Main Tabs under the Customize Ribbon. Click on the checkbox behind the Developer option to enable it on Outlook. 
  4. Click OK; the Developer tab is now available among the Outlook tabs.
The Developer is an option under the Main Tabs under the Customize Ribbon. Click on the checkbox behind the Developer option to enable it on Outlook

How to run Macros in Outlook?

Unlike macros in Excel, you can’t record a macro in Outlook. Therefore, it should be created using Visual Basic for the Application. It’s so simple; even if you are a beginner, there are many ready-to-use scripts that you can employ in your Outlook. Here are the most useful macros in Outlook. 

  • To start writing VBA codes as Outlook macro, click on the Visual Basic under the Code section of the Developer tab. 
  • Visual Basic for Applications will open. Double-click on ThisOutlookSession to open the code window. You can write or paste the scripts we mention in the following examples in this window and save them as an.OTM file. 
click on Visual Basic in Developer tab, ThisOutlookSession opens the code window, write or paste the scripts in this window and save them as an OTM file.
  • Any script you write and save will be displayed in the Macros. So, you can click on the Macros in Outlook and select the Macro name to run. 

How to send an Email automatically in Outlook?

One useful Outlook Macro is creating and sending an Email automatically. You only need to write a few lines of code in VBA, and the next time you open your Outlook, the message will be sent without you having to do anything. Assume you were on vacation and want your co-worker to know you are back to work. You can create a message, either send it yourself or have Outlook send it programmatically. 

Copy and paste these codes into VBA. 

Public Sub CreateMail()
Dim MyEmail As MailItem
Set MyEmail = Application.CreateItem(olMailItem)
With MyEmail
.To = “[email protected]
.Subject = “I’m back to work”
.Body = “We can start our new project”
.CC = “[email protected]
End With
MyEmail.Display 
End Sub

This script displays the created message when you open Outlook. If you want it to send the message automatically, you should change MyEmail.Display with MyEmail.Send.

.CC is an optional code; you can remove it from the script if you don’t want to send the message to anyone else. 

 

 

How to attach a file to an Email?

You may need your automatic message to have an attachment. Add this code to the body of the previous script (before End With). 

.Attachments.Add AttachFolder & AttachFile

  • Make sure you have entered the correct path and file name. 
  • You can add several recipients in each email using Outlook macro. Then, separate them with an “;”. 

How to automatically archive Emails in Outlook?

Macros can be your assistants in categorizing and archiving your emails. By writing VBA codes, you can make Outlook move an email to another folder based on the subject. However, the newest version of Outlook has an Archive button that you can use instead of creating a macro. Write these codes if you want to know how to auto-archive specific emails in Outlook.

Sub ArchiveMessage1()
 ‘On Error Resume Next
Dim objNameSpace As Outlook.NameSpace
 Dim objInbox As Outlook.MAPIFolder
 Dim objDestFolder As Outlook.MAPIFolder
 Dim objItem As Outlook.MailItem
Set objNameSpace = Application.GetNamespace(“MAPI”)
 Set objInbox = objNameSpace.GetDefaultFolder(olFolderInbox)
 Set objDestFolder = objInbox.Folders(“_FOLDER_”)
 ‘various other options here:
 ‘works to select root folder:
 ‘Set objDestFolder = objNameSpace.Folders(“Mailbox – _NAME_”).Folders(“_FOLDER_”)
 ‘works as picker:
 ‘Set objDestFolder = objNameSpace.PickFolder
 
‘If no message selected, then
 If Application.ActiveExplorer.Selection.Count = 0 Then
     MsgBox (“No item selected”)
     Exit Sub
 End If
 
‘If folder doesn’t exist, then
 If objDestFolder Is Nothing Then
     MsgBox “This folder doesn’t exist!”, vbOKOnly + vbExclamation, “INVALID FOLDER”
 End If
 
‘For each item selected, do the following
 For Each objItem In Application.ActiveExplorer.Selection
     If objDestFolder.DefaultItemType = olMailItem Then
         If objItem.Class = olMail Then
             objItem.Move objDestFolder
         End If
     End If
 Next
 
Set objNameSpace = Nothing
Set objInbox = Nothing
Set objDestFolder = Nothing
Set objItem = Nothing
 
End Sub

How to turn off auto archive in Outlook?

Archiving messages in Outlook is very useful. You can set a period for auto-archiving messages and turn the auto archive off anytime you want. Follow these steps:

  1. Go to File > Options
  2. Click on the Auto Archive button, which is under the Advanced tab. 
  3. A window will open, enable the Run AutoArchive and add the number of days you want this automatic task to run. 
  4. You can turn off auto archive in Outlook by disabling the Run AutoArchive
Go to File > Options. Click on the Auto Archive button under the Advanced tab, enable the Run AutoArchive, and add the number of days.

How do I automatically run a Macro in Outlook?

Any VBA script that starts with Application_Startup() will run whenever Outlook starts. Check the example below: 

Private Sub Application_Startup()
  CreateAppointment
End Sub
 
Private Sub Application_Reminder(ByVal Item As Object)
Set olRemind = Outlook.Reminders
 
If Item.MessageClass <> “IPM.Appointment” Then
  Exit Sub
End If

In this blog, we shared some suggestions and guidelines about how outlook could be adjusted to reduce repetitive tasks. We covered sending emails automatically, auto-archive and file attachments. 

FAQ

Does Outlook have a macro recorder?

Outlook doesn’t have a macro recorder like Excel. Therefore, it’s not possible to record any task. All the macros in Outlook should be written in VBA codes. 

How do I enable Macros in Outlook VBA?

You should know that macros are not enabled in Outlook by default. If you don’t allow macros to run in Outlook, it will show you an error and ask you to enable macros. To do so, go to Macro Security under the Code section of the Developer tab.

What can VBA do in Outlook?

There are different tasks that you can do in Outlook using VBA codes. From sending emails to archiving them in another folder, you can make Outlook automatically do some useful tasks. 

Our experts will be glad to help you, If this article didn't answer your questions.

Share now:

About the Author: Vida.N

Leave A Comment

contact us

Contact us today at and speak with our specialist.