全部显示

Find 方法

       

应用于 Items 对象的 Find 方法。

应用于 UserProperties 对象的 Find 方法。

示例

本 Visual Basic for Applications 示例查找联系人的名为“LastDateContacted”的自定义属性。

Sub FindContact()
'Finds and displays last contacted info for a contact

    Dim olApp As Outlook.Application
    Dim objContact As ContactItem
    Dim objContacts As MAPIFolder
    Dim objNameSpace As NameSpace
    Dim objProperty As UserProperty

    Set olApp = CreateObject("Outlook.Application")
    Set objNameSpace = olApp.GetNamespace("MAPI")
    Set objContacts = objNameSpace.GetDefaultFolder(olFolderContacts)
    Set objContact = objContacts.Items.Find("[FileAs] = ""Smith, Jeff"" and [FirstName] = ""Jeff""")
    If Not TypeName(objContact) = "Nothing" Then
        Set objProperty = objContact.UserProperties.Find("LastDateContacted")
        If TypeName(objProperty) <> "Nothing" Then
            MsgBox "Last Date Contacted: " & objProperty.Value
        End If
    Else
        MsgBox "Contact not found."
    End If
End Sub