Function GetOneNameViaCDO()
Const cdoE_USER_CANCEL = &H80040113
' start CDO session
Set objSession = CreateObject("MAPI.Session")
objSession.Logon , , False, False
On Error Resume Next
Set colCDORecips = objSession.AddressBook(, _
"Pick a Name", , , 1, _
"My Choice")
If Err = 0 Then
If colCDORecips.Count <> 1 Then
MsgBox "Please choose exactly 1 name.", , _
"Chose One Name"
Else
strName = _
colCDORecips.Item(1).AddressEntry.Name
If Err = 287 Then
' security block triggered
MsgBox "Outlook cannot return " & _
"a name, because " & _
"you clicked No on the " & _
"e-mail address access " & _
"dialog. You need to try " & _
"again and click Yes " & _
"this time.", , _
"E-mail Address Access"
End If
End If
ElseIf Err = cdoE_USER_CANCEL Then
' user canceled the address book dialog -
' do nothing or provide a message to user
End If
GetOneNameViaCDO = strName
' release objects
objSession.Logoff
Set colCDORecips = Nothing
Set objSession = Nothing
End Function
Nenhum comentário:
Postar um comentário