Problem retireving Outlook contacts
Power Query Course in Spanish
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Problem retireving Outlook contacts

  1. #1
    Guest

    Default

     
    This is driving me crazy. As I see it the following code snippet should list everyone in my Outlook Contacts folder. It almost does, it seems to miss the newest entries. I'm sure it's something simple, any suggestions?

    ...
    Dim olapp As Outlook.Application
    Dim nspNameSpace As Outlook.NameSpace
    Dim fldContacts As Outlook.MAPIFolder
    Dim objContacts As Object
    Dim objContact As Object
    Dim iRow As Integer
    Dim sName As String

    On Error GoTo Err_Handler

    Set olapp = CreateObject("Outlook.Application")
    Set nspNameSpace = olapp.GetNamespace("MAPI")
    Set fldContacts = nspNameSpace.GetDefaultFolder(olFolderContacts)
    Set objContacts = fldContacts.Items
    iRow = 1
    For Each objContact In objContacts
    sName = objContact.FileAs
    Cells(iRow, 1).Value = sName
    Next objContact
    ...

  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    2,936
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default

    I've just tried your code (slightly modified) and it works fine, even if I add a new contact and then run it again.

    Sub GetOutlookContacts()

    Dim olapp As Outlook.Application
    Dim nspNameSpace As Outlook.NameSpace
    Dim fldContacts As Outlook.MAPIFolder
    Dim objContacts As Object
    Dim objContact As Object
    Dim iRow As Integer
    Dim sName As String

    On Error GoTo Err_Handler

    Set olapp = CreateObject("Outlook.Application")
    Set nspNameSpace = olapp.GetNamespace("MAPI")
    Set fldContacts = nspNameSpace.GetDefaultFolder(olFolderContacts)
    Set objContacts = fldContacts.Items
    iRow = 1
    For Each objContact In objContacts
    sName = objContact.FileAs
    Cells(iRow, 1).Value = sName
    iRow = iRow + 1
    Next objContact

    Exit Sub

    Err_Handler:

    MsgBox Err.Description

    End Sub


    HTH,
    D

  3. #3
    Guest

    Default

      
    Thanks, My Bad... I'd messed up the in the error handling routine.

    Thanks for the help. Tony

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com