Web development India freelance website designer developer India SEO

List all contacts stored in all Outlook contactfolders

Description:This peace of code shows you how to obtain all the contacts as been stored in your Outlook pst-file. No matter
how many contact-folders you have and how deep the three might be. (tested with Outlook 2000)


Private objApp As Outlook.Application
Private objNS As Outlook.NameSpace
Private objFolder As Outlook.MAPIFolder
Private objItem As Outlook.ContactItem
Private colAdressFolders As Collection


Sub Main()

Dim lngLoop As Long
Set objApp = New Outlook.Application
Set objNS = objApp.GetNamespace("MAPI")
Set colAdressFolders = New Collection
Set objFolder = objNS.Folders.GetFirst' get root-folder

' recursive loop thrue all folders to collect the references to Adressbooks
For lngLoop = 1 To objFolder.Folders.Count

If objFolder.Folders.Item(lngLoop).DefaultItemType = olContactItem Then
RecursiveSearch objFolder.Folders.Item(lngLoop), colAdressFolders
End If
Next lngLoop

' open every contact-folder and loop all entries
For Each objFolder In colAdressFolders

For lngLoop = 1 To objFolder.Items.Count
Set objItem = objFolder.Items(lngLoop)
Debug.Print objFolder.Name, objItem.FileAs
Next lngLoop
Next

End Sub


Private Sub RecursiveSearch(objSubFolder As Outlook.MAPIFolder, colAdrFolders As Collection)

On Error Goto Errorhandler
Dim lngLoop As Long
' check for entries in this subfolder

If objSubFolder.Items.Count > 0 Then
'add reference to collection
colAdrFolders.Add objSubFolder
End If
' check for subfolders

If objSubFolder.Folders.Count > 0 Then

For lngLoop = 1 To objSubFolder.Folders.Count
RecursiveSearch objSubFolder.Folders.Item(lngLoop), colAdrFolders
Next lngLoop
End If
Exit Sub
Errorhandler:
MsgBox "An unexpected Error occured methode RECURSIVESEARCH", vbCritical + vbOKOnly, "Problem"
Err.Clear
End Sub
List all contacts stored in all Outlook contactfol

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150

India web developer web development India | India web development company India ecommerce web developer