Friday, November 11, 2011

OutlookBarGroup Events


OutlookBarGroup Events

The events in this section fire when an OutlookBarGroup object is added or removed, either programmatically or through a user action.

GroupAdd

The GroupAdd event occurs after a group has been added to an Outlook Bar, either because of a user action or through program code. The following example adds shortcuts for all the members of a distribution list named Shared Calendars to a new group named Workgroup Calendars. All the members of the Shared Calendars distribution list must grant at least Reviewer permission on their calendar folders for this example to work correctly.
Private Sub colOutlookBarGroups_GroupAdd(ByVal NewGroup As OutlookBarGroup)
    DebugWrite "OutlookBarGroups GroupAdd " & NewGroup.Name
    Dim myFolder As Outlook.MAPIFolder
    Dim myRecip As Outlook.Recipient
    Dim myDL As Outlook.DistListItem
    On Error Resume Next
    Set myFolder = objNS.GetDefaultFolder(olFolderContacts)
    Set myDL = myFolder.Items("Shared Calendars")
    For i = 1 To myDL.MemberCount
        Set myRecip = objNS.CreateRecipient(myDL.GetMember(i).Name)
        myRecip.Resolve
        If myRecip.Resolved Then
            Set myFolder = _
            objNS.GetSharedDefaultFolder(myRecip, olFolderCalendar)
        End If
        NewGroup.Shortcuts.Add myFolder, "Calendar - " & myRecip.Name
    Next
    NewGroup.Name = "Shared Calendars"
End Sub

BeforeGroupAdd

The BeforeGroupAdd event occurs before a group is added to an Outlook Bar, either because of user action or through program code. This example prevents a user from adding groups to the Outlook Bar.
Private Sub colOutlookBarGroups_BeforeGroupAdd(Cancel As Boolean)
    Cancel = True
End Sub

BeforeGroupRemove

The BeforeGroupRemove event occurs before a group is removed from an Outlook Bar, either because of user action or through program code. The code in this example cancels an attempt by a user or program code to delete the Outlook Shortcuts group.
Private Sub colOutlookBarGroups_BeforeGroupRemove _
  (ByVal Group As OutlookBarGroup, Cancel As Boolean)
    If Group.Name = "Outlook Shortcuts" Then
        Cancel = True
    End If
End Sub

No comments:

Post a Comment