VBA (or Visual Basic for Applications) is the easy programming language that all Microsoft Office applications provide so that you can add extra function into Office. It’s very useful.
Before you can use VBA, you need to tell Outlook you want to do so. You do that by enabling the Developer Tab. In Outlook 2010 you can enable the developer tab very easily as follows:
- On the File tab, choose Options to open the Outlook Options dialog box.
- Click Customize Ribbon on the left side of the dialog box.
- Under Choose commands from on the left side of the dialog box,
select Popular Commands.
- Under Customize the ribbon on the right side of the dialog box, select Main tabs, and then select the Developer check box.
You should now see the developer tab on the main Outlook 2010 ribbon:
Once you have the Developer tab in Outlook 2010, you can start creating macros. Macros are little bits of code that you can write to do some pretty sophisticated stuff in Outlook. To create a Macro, click on Macros on the Developer Tab
Now enter a macro name and press “Create”
You can create macros to do loads of things. The macro below will just say “hello world”
Here’s the code you can cut n paste in:
On Error GoTo Qlockwork_err
‘ COMMENT: create a namespace, Outlook usually needs this
Dim ns As NameSpace
Set ns = GetNamespace(“MAPI”)
‘ COMMENT: Say Hi
MsgBox “Hello world!”
‘ COMMENT: Clean up after ourselves
Set ns = Nothing
‘ Handle errors
MsgBox “An unexpected error has occurred.”
Once you have created your macro, save it using the save button then click Debug->Compile Project to compile it (basically get it ready to run)
Then you can test it by choosing run->run:
At this point you’ll probably see a security error. You have 2 choices:
- you can digitally sign the macro (Tools->Digital Signature) if you have a code signing certificate
- alternatively, just go to Macro Security on the Developer Tab:
- then set the security to “Notify” on all macros (from notify on all signed macros) click OK and restart Outlook.
- Don’t forget to restart Outlook after doing this.
This simple macro is not very useful in itself but it shows you the basic operations of a macro. For more on macros see Outlook 2010 tips, how to run a simple macro on all new emails
At Qlockwork, Outlook development is what we do, so we are big fans. We are also big fans of automating things you do every day and saving time. Tasks you do all the time in Outlook really add up over the years. If you can write macros to do stuff for you, they’ll make you much more efficient!
If you want to find out how much time you currently spend in Outlook or any other Windows application then try the Qlockwork free trial from our Downloads page. Qlockwork automatically works out exactly how you spend your time on your PC.