GroupAdd Event Example

This example adds a shortcut to a group when the group is created. The sample code must be placed in a class module, and the Initialize_handler routine must be called before the event procedure can be called by Microsoft Outlook.

Dim myOlApp As New Outlook.Application
Dim WithEvents myOlGroups As Outlook.OutlookBarGroups
Dim myOlBar As Outlook.OutlookBarPane

Sub Initialize_handler()
    Set myOlBar = myOlApp.ActiveExplorer.Panes.Item("OutlookBar")
    Set myOlGroups = myOlBar.Contents.Groups
End Sub

Private Sub myOlGroups_GroupAdd(ByVal NewGroup As Outlook.OutlookBarGroup)
    Dim myFolder As Outlook.MAPIFolder
    Set myFolder = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar)
    NewGroup.Shortcuts.Add myFolder, "Calendar"
End Sub