[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

Extracting Email Addresses from the Outlook Contacts Folder and Contacts sub-directories

Hello all:

The Question Title pretty much says it all.

I am running Outlook 2002 on Windows XP Pro and I need to extract all the email addresses from the Contacts folder and all its subdirectories (there are a few I'm afraid).

Is there an easy way of doing this?

Thank you very much for any help.

  • 6
  • 5
1 Solution
David LeeCommented:
Hi driven13,
> I need to extract all the email addresses from the Contacts folder and
> all its subdirectories

And do what with them?  Write them to a file, display them onscreen?  

driven13Author Commented:
Hello BlueDevilFan:

I would like to extract them to an excel docement if I could.  I am trying to create a whitelist for myself.

Thank you,

David LeeCommented:
How about a TSV file?  Would that be good?  And do you only want the email address and nothing else?  Also, what about entries with multiple email addresses?  How would you like to handle them?
Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

driven13Author Commented:
A TSV should be fine.

I just require the email addresses, and that's it.

I need the multiple email addresses too but they are a few and far between.

My main concern for this whole process is that it needs to be able to extract the email addresses from the Contacts subfolders too and there are a bunch of them, sometimes 4 levels deep.

Thank you for your time.

David LeeCommented:
The depth of the nested folders isn't a problem.  I just wrote a macro that will delete an Outlook folder and all subfolders, so I can use it as the basis for this.  I'll have this posted shortly.
driven13Author Commented:

you are a life-saver!!

David LeeCommented:

Here's the macro.  Follow these instructions to use it.
1.  Start Outlook
2.  Click Tools->Macro->Visual Basic Editor
3.  If not already expanded, expand Modules and click on Module1
4.  Copy the code below and paste it into the right-hand pane of the VB Editor window
5.  Edit the code making the changes per the comments I embeded in the code
6.  Click the diskette icon on the toolbar to save the changes
7.  Close the VB Editor
8.  Click Tools->Macro->Security
9.  Set the Security Level to Medium
10.  Close Outlook
11.  Start Outlook
12.  Click on the Contacts folder and then run the macro (Tools->Macro->Macros->ExportFolderTree->Run)
13.  The macro will pop up a dialog-box asking if you want to export.  Click Yes to proceed or No to cancel
14.  When the macro accesses the first email address Outlook will pop up a dialog-box saying that a program is accessing you mailbox and asking for permission to continue.  Click the "allow access for" pulldown and select 5 minutes of access.  That's all there is to it.  When it's finished you should have a TSV file loaded up with addresses.  I wrote and tested this using Outlook 2002 and it worked exactly as I've described.

'Macro Begins Here
Dim objFSO, objFile

Sub ExportFolderTree()
    Dim olRootFolder As MAPIFolder, _
        olExplorer As Outlook.Explorer, _
        intCounter As Integer
    Set olExplorer = Application.ActiveExplorer
    Set olRootFolder = olExplorer.CurrentFolder
    If MsgBox("Export email addresses from [" & olRootFolder.Name & "] and all its sub-folders?", vbYesNo, "Export Folder Tree") = vbYes Then
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        'Change the file name and path on the next line as desired
        Set objFile = objFSO.CreateTextFile("C:\EmailAddresses.tsv")
        ProcessFolder olRootFolder
    End If
    Set olRootFolder = Nothing
    Set olExplorer = Nothing
    Set objFile = Nothing
    Set objFSO = Nothing
    MsgBox "All done.", vbInformation, "Export Folder Tree"
End Sub

Sub ProcessFolder(olFolder As MAPIFolder)
    Dim olMyContact As Object, _
        objFolder As MAPIFolder, _
        strBuffer As String
    If olFolder.Folders.Count > 0 Then
        For Each objFolder In olFolder.Folders
            ProcessFolder objFolder
    End If
    If olFolder.Items.Count > 0 Then
        For Each olMyContact In olFolder.Items
            If olMyContact.Class = olContact Then
                With olMyContact
                    strBuffer = IIf(.Email1Address <> "", .Email1Address & vbTab, "")
                    strBuffer = strBuffer & IIf(.Email2Address <> "", .Email2Address & vbTab, "")
                    strBuffer = strBuffer & IIf(.Email3Address <> "", .Email3Address & vbTab, "")
                End With
                If strBuffer <> "" Then
                    objFile.WriteLine strBuffer
                End If
            End If
    End If
    Set olFolder = Nothing
    Set olMyContact = Nothing
End Sub
'Macro Ends Here
How  about using export?

File > Import and Export...> Choose "Export to a file..." and Next > Choose "Microsoft Excel and Next > Choose "Contacts" folder and Next > give the address book a name and Next > Next and then Finish

driven13Author Commented:
BlueDevilFan:  I will try it out and let you know ASAP.  You are the best!

itchopin:  Your method, unfortunately, does not work with multiple levels of Contacts folders.

Thank you, both.

David LeeCommented:

driven13Author Commented:

It worked beautifully!!!

Thank you very much for your expertise and for your time.

I have two small questions for you:

1)  Can I use this same macro to get email addresses from other folders inside Outlook?

2)  Will this macro work with Outlook 2003 if I wanted to extract the email addresses from the Contacts folder and sub-folders?

Again, appreciate it.

David LeeCommented:

You're welcome.  I'm glad to have been able to help out.  In answer to your questions:

1.  Yes, so long as the folders involved are contact folders.
2.  It should.  I'd say give it a try and if you run into a problem post a message here and I'll fix whatever didn't work right.


Featured Post

Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now