Writing an Outlook Macro

A macro is any public subroutine in a code module. A function or a private subroutine cannot be a macro, and a macro cannot be located in a class or form module.

To create a new macro

  1. In Outlook, on the Developer tab of the Microsoft Office Fluent ribbon, click Visual Basic.

  2. In the Project window, double-click the module you want to contain the macro.

  3. On the Insert menu, click Procedure.

  4. In the Name box, type a name for the macro. The name cannot contain spaces.

  5. Click OK. The template for the macro subroutine appears in the code module window.

  6. Type the code you want to run in the body of the subroutine.

For more information about using the Visual Basic Editor, see the Visual Basic Editor Help. Once you've created a macro, you can create a menu item or toolbar button that will run the macro when you click it.

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.