Partager via


Links.Add Method (Outlook)

Links a contact item to another item by adding a Link object to the Links collection associated with the latter item.

Syntax

expression .AddItem

expression A variable that represents a Links object.

Parameters

Name

Required/Optional

Data Type

Description

Item

Required

Object

The item to be linked to the item associated with the Links collection.

Example

This Microsoft Visual Basic for Applications (VBA) example creates a new task item, and then prompts the user for the name of a contact to link to the item. If the contact is found, it is added to the item’s Links collection.

Sub AddLink() 
 
 Dim myNameSpace As Outlook.NameSpace 
 
 Dim myFolder As Outlook.Folder 
 
 Dim myTask As Outlook.TaskItem 
 
 Dim myContact As Outlook.ContactItem 
 
 Dim myItems As Outlook.Items 
 
 Dim tempstr As String 
 
 
 
 Set myTask = Application.CreateItem(olTaskItem) 
 
 Set myNameSpace = Application.GetNamespace("MAPI") 
 
 Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts) 
 
 tempstr = InputBox("Enter the name of the contact to link to this task") 
 
 If tempstr <> "" Then 
 
 tempstr = "[Full Name] = """ & tempstr & """" 
 
 Set myItems = myFolder.Items.Restrict("[MessageClass] = 'IPM.Contact'") 
 
 Set myContact = myItems.Find(tempstr) 
 
 myTask.Links.Add myContact 
 
 myTask.Display 
 
 End If 
 
End Sub

See Also

Concepts

Links Object

Links Object Members