Friday, November 11, 2011

OutlookBarShortcut Events


OutlookBarShortcut Events

The OutlookBarShortcut events occur when an OutlookBarShortcut object is added or removed, either programmatically or through a user action.

ShortcutAdd

The ShortcutAdd event fires after a shortcut has been added to an Outlook Bar group, either because of user action or through program code. The following event procedure adds the name of the logged-on user to the shortcut name if the user adds a shortcut to his or her Calendar folder:
Private Sub colOutlookBarShortcuts_ShortcutAdd _
  (ByVal NewShortcut As OutlookBarShortcut)
    On Error Resume Next
    Dim objFolder As Outlook.MAPIFolder
    Set objFolder = NewShortcut.Target
    'Bail out if not a folder shortcut
    If Err Then Exit Sub
    'Test EntryID's to determine if folder shortcut 
    'is for user's calendar folder
    If objNS.GetDefaultFolder(olFolderCalendar).EntryID = _
      objFolder.EntryID Then
        NewShortcut.Name = "Calendar - " & objNS.CurrentUser
    End If
End Sub

BeforeShortcutAdd

The BeforeShortcutAdd event takes place before a shortcut is added to an Outlook Bar group, either because of user action or through program code. This example prevents users from adding a shortcut to the Web Links group. Objects representing the current group on the Outlook Bar and the collection of shortcuts for the current group are instantiated in the BeforeGroupSwitch event of the Pane object.
Public objCurrentGroup As Outlook.OutlookBarGroup

Private Sub objPane_BeforeGroupSwitch(ByVal ToGroup As OutlookBarGroup, _
    Cancel As Boolean)
    Set colOutlookBarShortcuts = ToGroup.Shortcuts
    Set objCurrentGroup = ToGroup
End Sub

Private Sub colOutlookBarShortcuts_BeforeShortcutAdd(Cancel As Boolean)
    If objCurrentGroup.Name = "Web Links" Then
        Cancel = True
    End If
End Sub

BeforeShortcutRemove

The BeforeShortcutRemove event takes place before a shortcut is removed from an Outlook Bar group, either because of user action or through program code. The code in this example cancels an attempt by users or program code to delete a shortcut from the Financial Services group.
Private Sub colOutlookBarShortcuts_BeforeShortcutRemove(Cancel As Boolean)
    If objCurrentGroup.Name = "Financial Services" Then
        Cancel = True
    End If
End Sub

No comments:

Post a Comment