Target Property Example

This Microsoft Visual Basic/Visual Basic for Applications example steps through the shortcuts in the first Outlook Bar group. If it finds a shortcut that is not an Outlook folder, it deletes it.

Dim myOlApp As New Outlook.Application
Dim myOlBar As Outlook.OutlookBarPane
Dim myolGroup As Outlook.OutlookBarGroup
Dim myOlShortcuts As Outlook.OutlookBarShortcuts
Dim myOlShortcut As Outlook.OutlookBarShortcut
Set myOlBar = myOlApp.ActiveExplorer.Panes.Item("OutlookBar")
Set myolGroup = myOlBar.Contents.Groups.Item(1)
Set myOlShortcuts = myolGroup.Shortcuts
myTop = myOlShortcuts.Count 
For x = myTop To 1 Step -1
    Set myOlShortcut = myOlShortcuts.Item(x)
    If TypeName(myOlShortcut.Target) <> "MAPIFolder" Then
        myOlShortcuts.Remove x
    End If
Next x

If you use VBScript, you do not create the Application object. This example shows how to perform the same task using VBScript.

Set myOlBar = _
    Application.ActiveExplorer.Panes.Item("OutlookBar")
Set myolGroup = myOlBar.Contents.Groups.Item(1)
Set myOlShortcuts = myolGroup.Shortcuts
myTop = myOlShortcuts.Count 
For x = myTop To 1 Step -1
    Set myOlShortcut = myOlShortcuts.Item(x)
    If TypeName(myOlShortcut.Target) <> "MAPIFolder" Then
        myOlShortcuts.Remove x
    End If
Next