How to Run VBA Code in Your Outlook

At times you may wish to utilize VBA code in Outlook to achieve more functions. Yet, you do not know how to run VBA code in your Outlook. Thus, this article will expose the detailed steps to you.

Thereinafter, we will take Outlook 2010 version as an example and show you the elaborate steps, ranging from modifying macro security settings to running VBA code. Now, read on to get them.

Step 1: Enable “Developer” Tab

  1. First of all, after launching Outlook, access “File” menu.Access File Menu
  2. Then, in “File” menu, select and click on “Options”.Select Options in File Menu
  3. Next, in the popup “Outlook Options” window, switch to “Customize Ribbon”.
  4. Later, on the right side, you can find out and enable the “Developer” tab.Enable the “Developer” Tab
  5. Lastly, click “OK”.

Step 2: Check Macro Security Settings

  1. After returning to Outlook main window, you can access “Developer” ribbon.
  2. Then, click on the “Macro Security” button.Open Macro Security
  3. In the subsequent screen, you should select “Notifications for all macros” and hit “OK” button.Change Macro Security

Step 3: Access Outlook VBA Editor

To run VBA code, you have to access the VBA editor firstly, which can be achieved by the following 2 means:

  1. In Outlook, under the “Developer” tab, click on the “Visual Basic” button.Access VBA Editor by "Visual Basic" Button
  2. Or you can directly press “Alt + F11” key buttons.

Step 4: Add VBA Code

  1. In VBA editor, namely “Microsoft Visual Basic for Applications” window, you need to expand the “Microsoft Outlook Objects” folder on left side
  2. Then, double click on the “ThisOutlookSession” project to open it.Open “ThisOutlookSession” Project
  3. Subsequently, you can copy and paste your VBA code into the white editing pane of this project.Paste VBA Code
  4. Optionally, you can copy the VBA code into a module.
  • Click “Insert” button in the menu bar.
  • Choose “Module” from the drop down list.Insert New Module
  • Then, a new module will display. Now you can copy code into the module as usual.New Module

Note: In general, you can paste the code into either “ThisOutlookSession” or a module. But, the VBA code involving events, like “Application_Start”, must be put in “ThisOutlookSession”.

Step 5: Run VBA Code

After adding the macro, you can run it. In the macro window, you can press “F5” key button or click on the “Run” button in the toolbar.Run VBA Code

Note: For the VBA code involving events, like “Application_Start”, you ought to restart your outlook to activate it.

Optional Step: Add Macro to Quick Access Toolbar or Ribbon

If you would like to run macro in the main Outlook window instead of in the VBA editor, you can add the macro to Quick Access Toolbar or ribbon.

Add Macro to Quick Access Toolbar

  1. First off, access “Outlook Options” by following the operations shown in Step 1, in which you can shift to “Quick Access Toolbar” tab.
  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”.Add Macro to Quick Access Toolbar
  6. Since then, to run this macro, you can simply click the macro button in Quick Access Toolbar.Run Macro through Quick Access Toolbar

Add Macro to Ribbon

  1. At first, go to “File” menu and click “Options”.
  2. In the subsequent “Outlook Options” window, turn to “Customize Ribbon”.
  3. Then, on the right side, click “New Group” button.Create New Group in Ribbon
  4. Next, click “Rename” button.
  5. In the popup dialog box, specify a name and icon for the new group, such as “Smart Move” in my instance, and click “OK”.Rename New Group
  6. Later, on the left side, select “Macros” from the drop-down list of “Choose Commands from”.
  7. After that, in the macro list, select the macro you want.
  8. Then, click “Add >>” button in center to add this macro to the custom group.Add Macro to New Group
  9. Next, click “Rename” button.
  10. In the new dialog box, change the name of this macro and assign an icon to it.Rename the Macro Button
  11. Ultimately, click a series of “OK” until getting back to Outlook main window.
  12. Now, you will see the new macro button in ribbon, as shown in the following screenshot.New Macro Button in Ribbon

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including mdf recovery and outlook repair software products. For more information visit www.datanumen.com

Comments are closed.