Add Method (Inspectors Collection) Example
This Microsoft Visual Basic/Visual Basic for Applications example prompts the user for a company name, uses the Restrict method to locate all contact items in the Contacts folder with that name, and displays each one.
Dim myOlApp As New Outlook.Application
Answer = InputBox("Enter the company name")
Set myFolder = myOlApp.GetNamespace("MAPI") _
.GetDefaultFolder(olFolderContacts)
Set myItems = myFolder.Items.Restrict("[MessageClass] = 'IPM.Contact'")
Set myRestrictItems = myItems.Restrict("[CompanyName] = " & Answer)
For x = 1 To myRestrictItems.Count
Set myInspector = myOlApp.Inspectors.Add(myRestrictItems.Item(x))
myInspector.Display
Next x
If you use VBScript, you do not create the Application object, and you cannot use named constants. This example shows how to perform the same task using VBScript.
Answer = InputBox("Enter the company name")
Set myFolder = _
Application.GetNamespace("MAPI").GetDefaultFolder(10)
Set myItems = myFolder.Items.Restrict("[MessageClass] = 'IPM.Contact'")
Set myRestrictItems = myItems.Restrict("[CompanyName] = " & Answer)
For x = 1 To myRestrictItems.Count
Set myInspector = Application.Inspectors.Add(myRestrictItems.Item(x))
myInspector.Display
Next