
Installation and running macros
tags: toolbar, outlook 2007, MS Outlook, Microsoft Outlook, macro, email client, e-mail
0 comments | Add a comment
This article applies to: Microsoft Outlook 2000/2002/2003
Contents:
Introduction
Installation and running macros
Running macros from the toolbar
Macros’ security levels
Introduction
In Microsoft Office Outlook, like in other Microsoft Office applications, you can create macros that will automate frequently used operations and save you valuable time. Macros are created in the programming language called Visual Basic for Application (VBA), using object modeling (objects) in Outlook. There are many different objects in Outlook and each one has a set of features, methods and events. On the one hand, you can create macros that speed up and facilitate user’s work or even implement some feature that are not included in Outlook. On the other hand, a wide range of objects, their features and options means that you need some time to get familiar with all of them in order to use them conveniently. Fortunately, the Internet is full of various macros that are useful and able to solve your problems. Sometimes you just need to make some minor changes, other times they are ready to use. Even less experienced users who don’t know objects in Outlook, or know them very superficially, can use macros in their every-day work. They should, however, be familiar with how to properly install and run macros on the machine.
Installation and running macros
When you already have a macro first you need to type it in the Visual Basic editor before you can run it in Outlook. Visual Basic editor is a separate application in Outlook. Go to Tools, Macro, Visual Basic Editor or simply use the short key Alt+F11 (Visual Basic Editor is only available in English) to open Visual Basic Editor (Fig.1).

Fig.1 Visual Basic Editor in Microsoft Outlook.
On the left side in the Project window you can see the current Project called Project1. When you click and expand it you will see a folder Microsoft Outlook Objects, and inside a module ThisOutlookSession. You have to type your macro codes in this module. Project1 is the only project that can exist in Outlook, you can neither delete it nor create a new one; you may only change its name. If you plan to use a number of macros you can add additional modules and put your macros inside. To create a new module you need to click right mouse button on the Project window and from the context menu choose Insert, Module. Macros that you create in other modules may be used in Outlook the same way as those created in ThisOutlookSession module. However, there is one exception. If the macro uses events from Outlook objects then it must be placed in the ThisOutlookSession module. You can recognize an event macro by looking for a variable including WithEvents – there must be at least one.
Let’s try this macro that creates a new HTML message with specified subject and body:
Sub CreateHTMLMail()
Dim oMail As MailItem
Set oMail = Application.CreateItem(olMailItem)
oMail.HTMLBody = "<b>Hello</b>, <br>this is the message body"
oMail.Subject = "Test HTML"
oMail.Save
End Sub
After you copy the code into the ThisOutlookSession module or another, you can close the Visual Basic editor. Now, you need to run the macro: in Outlook menu go to Tools, Macro, Macros or use the Alt+F8 shortcut. A window containing available macros will display. On the list choose macro called ThisOutlookSession.CreateHTMLMail and click Run (Fig.2).

Fig.2 Running macros.
Running macros from the toolbar
You can create your own toolbar with the most frequently used macros in Outlook. To create a new customized toolbar follow these steps:
1. In Outlook menu go to Tools, Customize.
2. Go to the Toolbars tab and click New.
3. Name your new toolbar (e.g. "Macros") and click OK. (Fig.3).
4. Do not close the Customize window – we will need it soon.
A newly created empty toolbar will be displayed.

Fig.3 Creating a new toolbar.
To create on the new toolbar a button to run the macro "CreateHTMLMail":
1. On the Customize window go to the Commands tab.
2. On the Categories list choose Macros.
3. On the Commands list choose macro called "Project1.ThisOutlookSession.CreateHTMLMail" and drag-and-drop it with your mouse onto the Macros toolbar (Fig.4). You can drag the macro onto one of the standard toolbars, or even drop it inside the Outlook menus. If you placed the macro in ThisOutlookSession module, its name will look like this: Project1.ThisOutlookSession.CreateHTMLMail. If you can’t see your macro, restart the Outlook and come back to this step.

Fig.4 Creating a new toolbar.
4. Now, click the right mouse button on the created button on the toolbar (Fig.5). You will see a menu containing options to modify the look of the button. Let’s change the name to a shorter one. In the menu click the field next to the line Name and put the name of the macro CreateHTMLMail. Hit Enter to confirm the changes.

Fig.5 Changing the button properties on the toolbar.
5. Let’s change the icon of the button. You can use the default icon for a new message that is used on the standard toolbar for the New button:
- To do that, first you need to make a screenshot, use the combination Alt+PrintScreen.
- Open the Paint application and paste the clipboard using Ctrl+V shortcut.
- Select the massage icon using the tool called Select. The selection must have exactly 16 per 16 pixels, otherwise the icon will be automatically stretched to fit this size and it will look bad.
- Copy the selection to the clipboard (you may use CTRL+C shortcut).
- Go back to Outlook and click right mouse button on the macro button on the toolbar (the Customize windows must be still open). From the menu choose the Paste Button Image option. The icon should be replaced with the one you selected in Paint.
- Now you can close the Customize dialog box.
After you click CreateHTMLMail on the Macros toolbar the macro will be run (Fig.6). This is a much simpler way to run the macros instead of going into the Macros menu in Tools. Now you may place the Macros toolbar next to other toolbars or even close it if you wish. You can restore it anytime by choosing View, Toolbars, Macros.

Fig.6 New toolbar with CreateHTMLMail button.
Macros’ security levels
In Outlook macros have various security levels that can be set on: Low, Medium, High, Very High. When the very high level is set up no macros can be run in Outlook. If you set up high level, only digitally signed macros can be run. Choosing medium level of security will display a warning message when you run the first macro in a session (Fig.7).

Fig.7 Warning message displayed on the medium security level.
Low security level means that all macros can be run without any restrictions. If you want to use macros in Outlook you need to set up security level on Medium or Low, or on High and then sign it digitally. You can set up macros’ security level in Tools, Macro, Security (Fig.8).

Fig.8 Changing macros’ security level.
You can find an example of a macro procedure here.
If you have any questions or comments concerning this article, please write on forum.
© All rights reserved. No part or whole of this article may not be reproduced or published without prior permission.
