Target Property

Microsoft Outlook Visual Basic

Returns a Variant indicating the target of the specified shortcut in a Shortcuts pane group. Read-only.

expression.Target

expression    Required. An expression that returns an OutlookBarShortcut object.

Remarks

The return type depends on the shortcut type. If the shortcut represents a Microsoft Outlook folder, the return type is MAPIFolder. If the shortcut represents a file-system folder, the return type is an Object. If the shortcut represents a file-system path or URL, the return type is a String.

Example

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

Sub DeleteShortcuts()
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
Dim myTop As Integer
Dim x As Integer
Set myOlBar = myOlApp.ActiveExplorer.Panes.Item("OutlookBar")
Set myolGroup = myOlBar.Contents.Groups.Item(1)
Set myOlShortcuts = myolGroup.Shortcuts
myTop = myOlShortcuts.Count
'Prompt the user for confirmation
Dim strPrompt As String
strPrompt = "Are you sure you want to remove all the shortcuts on the Shortcuts pane that are not Outlook folders?"
If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
    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
End If
End Sub
		

If you use Microsoft Visual Basic Scripting Edition (VBScript) in an Outlook form, you do not create the Application object. This example shows how to perform the same task using VBScript code.

Sub CommandButton1_Click()
 Set myOlBar = _
    Application.ActiveExplorer.Panes.Item("OutlookBar")
 Set myolGroup = myOlBar.Contents.Groups.Item(1)
 Set myOlShortcuts = myolGroup.Shortcuts
 myTop = myOlShortcuts.Count 
 'Prompt the user for confirmation
 Dim strPrompt
 strPrompt = "Are you sure you want to remove all the shortcuts on the Shortcuts pane that are not Outlook folders?"
 If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
 	For x = myTop To 1 Step -1
		 Set myOlShortcut = myOlShortcuts.Item(x)
	 	If TypeName(myOlShortcut.Target) <> "MAPIFolder" Then
		 	myOlShortcuts.Remove x
 		End If
 	Next
 End If
End Sub