View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Steve Yandl[_2_] Steve Yandl[_2_] is offline
external usenet poster
 
Posts: 37
Default Pull Recipient from Outlook Address book

Are you trying to get a specific name or the list of names from the address
book?

Here is a sub that would place the names of all your contacts in column A of
the active sheet beginning with A1.

'--------------------------------------------

Sub MyContactNames()

Const olContactFolder = 10

Dim R As Integer

Set objOL = CreateObject("Outlook.Application")
Set olNS = objOL.GetNamespace("MAPI")
Set myFolder = olNS.GetDefaultFolder(olContactFolder)
Set myItems = myFolder.Items

R = 1

For Each myContact In myItems
If TypeName(myContact) = "ContactItem" Then
Cells(R, 1).Value = myContact.FullName
R = R + 1
End If
Next myContact

Set olNS = Nothing
Set objOL = Nothing

End Sub

'--------------------------------------------

Steve Yandl



"BigPig" wrote in message
...
Hi All,

I'm trying to get an Outlook display name from an outlook address book and
put it in a text box. I can open the address book, but can't seem to find
a
way to get the display name. Any and all help would be greatly
appreciated.
See the script below. Thanks -BigPig-

Set appOutlook = CreateObject("Outlook.Application")
Set CDOSession = appOutlook.CreateObject("MAPI.Session")

CDOSession.Logon "", "", False, False, 0

On Error GoTo ErrHand
Set Recipients = CDOSession.addressbook(Nothing, "Address Book", False,
True, 1, "To:", "", "", 0)

Dim OLDN As String
OLDN = Recipients
Stop
txt_SUYI_OutL_Display_Name = OLDN
Set appOutlook = Nothing
Set CDOSession = Nothing

ErrHand:
Set appOutlook = Nothing
Set CDOSession = Nothing
Exit Sub

txt_SUYI_OutL_Display_Name = OLDN

Set appOutlook = Nothing
Set CDOSession = Nothing