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
- Setup an environment to enable us doing macro development
- Learn how to use Visual Basic editor to create a macro
- Run a macro
- Create shortcut for a macro
- 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.
On the pop-up Please follow the sequence mentioned in the picture and select Developers Tab
This will show up a new Tab named Developer in the Ribbon as follows.
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.
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.
Double click the module and start writing your codes on the editing pane on the right. To start with you may write the following:
Private Sub Appliclation_Startup() MsgBox ("Hello World!") End Sub
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!
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:
- Right click on empty place within quick access toolbar and select customize Quick Access Toolbar
- Next, select Macros from the Choose commands from
- Then, in the macro list, choose a macro
- After that, click Add button in center
- Finally, click OK
The last topic I would like to cover in this is the 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.
Hope this was helpful and you are ready to fly