How to create your first VBA Macro in Outlook

Home > Search > How-to
  by

When testing your Macro's, it is usually best to enable all macros.

  1. In the upper left-hand corner of Outlook, select File Options.
  2. In the left panel, select Trust Center.
  3. Select Trust Center Settings.
  4. In the left panel, select Macro Settings.
  5. Check Enable all macros.
  6. Select OK.
  7. In the left panel, select Customize Ribbon.
  8. Check Developer.
  9. Select OK.

There should now be a Developer option in the top ribbon of Outlook.

 


To create a simple VBA Macro:

  1. Press Alt + F11 (or select Developer > Visual Basic.
  2. In the left panel, expand Project1 > Microsoft Outlook Objects, and double-click ThisOutlookSession.
  3. Paste the following Markup in the right-panel of the Visual Basic editor.

 

Sub ChangeCurrentFolder()
    Dim myolApp As Outlook.Application
    Dim myNamespace As Outlook.NameSpace
    Set myolApp = CreateObject("Outlook.Application")
    Set myNamespace = myolApp.GetNamespace("MAPI")
    Set myolApp.ActiveExplorer.CurrentFolder = _
    myNamespace.GetDefaultFolder(olFolderCalendar)
End Sub
  1. Near the top of the Visual Basic editor, select the green play button. Outlook should display your Calendar.


Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments