Microsoft Outlook allows users to define macros written in Visual Basic for Applications (VBA) to automate certain activities. Through Visual Basic for Applications or VBA programming, you can automate almost every operation that you can perform with a mouse, keyboard, or a dialog box. We refer to this series of commands written in a logical sequence or VBA codes as Macros. Macro recorder is available for other Office applications, but unfortunately not available for Outlook. This was discontinued for Outlook due to security reasons in the past. So, for Outlook, it has to be done manually. This article will cover how to configure outlook for development, to on-board you on VBA programming. We will go step by step to show

  1. Setup an environment to enable us doing macro development
  2. Learn how to use Visual Basic editor to create a macro
  3. Run a macro
  4. Create shortcut for a macro
  5. How to Enable security

Setup of macro development environment

The first thing that you have to do to start - is to enable developers tab.

You can do it through Options, which you can invoke from File Tab in the Ribbon. Other easy way is to right click on empty place on the Quick Access Toolbar and browse to select Customize the Ribbon.

Cutomize-Quick-Access.png

On the pop-up Please follow the sequence mentioned in the picture and select Developers Tab

Show-Dvelopers-Tab.png

This will show up a new Tab named Developer in the Ribbon as follows.

Outlook-Developer-Tab

Visual Basic editor to create a macro

You may click Visual Basic to start with your coding. You can also press “Alt + F11” key buttons to open Visual Basic editor window.

VBA

In the popup window please expand Microsoft Outlook objects.You would see thisOutlookSession.please double click that and start writing your codes on the right side editing window. Here on the top right side you have a dropdown and anything that you select from that this will create a sub for that event.Events are triggered in a specific situations. Your code should go into do that sub.

In this example we are creating a message box which will address the world here you can also so call all different macro modules. Macro module can be created from Menu and then insert. This will create new module under module folder.

Insert Module.png

Double click the module and start writing your codes on the editing pane on the right. To start with you may write the following:

First macro VBA
Private Sub Appliclation_Startup()
	MsgBox ("Hello World!")
End Sub

Running Macro

Let's see how we can invoke those modules. One option is to run it from within the Visual Basic editor for applications. You click on somewhere in the body of the Sub and click on the run button on the top. In this example, the Sub is creating a Pop-up Message Window addressing the world!

Run-Macro.png
Hello-world.png

Create shortcut for a macro

You can add the macro to Quick Access Toolbar or ribbon to conveniently access them without opening the VBA

Here is how:

  1. Right click on empty place within quick access toolbar and select customize Quick Access Toolbar
  2. Next, select Macros from the Choose commands from
  3. Then, in the macro list, choose a macro
  4. After that, click Add button in center
  5. Finally, click OK

Macro-in-quick-access.png

The last topic I would like to cover in this is the security

Enable Security

From the developer Ribbon you can click on macro security. This will pop-up the trust centre. Please select the appropriate level of security .Press ok to complete it.

Macro-security.png

Hope this was helpful and you are ready to fly