![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
|
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 |
|
Guest
Posts: n/a
|
Thanks, My Bad... I'd messed up the in the error handling routine.
Thanks for the help. Tony |
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|