Solved

Modify script to extract First Name and Last name too...

Posted on 2007-11-28
2
648 Views
Last Modified: 2008-02-01
HI, the following code extracts the email addresses of everyone in my Outlook.

However, all it does is extract the email addresses - I need it to also extract the display name beside the email address.

This is just code that I have pasted into a notepad file and saved as 'extract.vbs' and run on my desktop.

Please assist:

=========================

Dim mailAddr()

Sub AddtoMailArray(addr)
    Dim isFound, arrLen
    isFound = False
    arrLen = getArrLength(mailAddr)
    If arrLen > -1 Then
        For I = 0 To arrLen
            If LCase(addr) = mailAddr(I) Then
                isFound = True
            End If
        Next
    End If
    If isFound = False Then
        ReDim Preserve mailAddr(arrLen + 1)
        mailAddr(arrLen + 1) = LCase(addr)        
    End If
End Sub

Function getArrLength(arr())
    err.clear
    On Error Resume Next    
    getArrLength = UBound(arr)
    if err.number <> 0 then getArrLength = -1
End Function


    Const olFolderSentMail = 5
    Const ForWriting = 2
   
    Dim OutLookApp, fdr, item, re
    Dim cnt
    Dim I
   
    Erase mailAddr
   
    On Error Resume Next
    Set OutLookApp = GetObject(, "Outlook.Application")
    If OutLookApp Is Nothing Then
        Set OutLookApp = CreateObject("Outlook.Application")
    End If
    On Error GoTo 0
    Set fdr = OutLookApp.GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail)
    cnt = 0
    For Each item In fdr.Items
               
        For Each re In item.Recipients
            If I = item.Recipients.Count Then
                  tmp = tmp & re.Address
            Else
                  tmp = tmp & re.Address & ", "
            End If
            AddtoMailArray re.Address            
        Next
        cnt = cnt + 1
        tmp = ""        
    Next
   
    FileName = "C:\test1.txt"
   
    Dim fso, file
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set file = fso.OpenTextFile(FileName, ForWriting, True)
    If getArrLength(mailAddr) > -1 Then
          For I = 0 To UBound(mailAddr)
                   file.Write mailAddr(I) & vbcrlf
        Next
    End If
    file.Close
    set file = nothing
    set fso = nothing
   
    MsgBox "Done!"

=======================
0
Comment
Question by:mharcais
2 Comments
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20365908
This should help. Sorry Since I dont have outlook , i am referring you the link
http://www.programmingmsaccess.com/Samples/VBAProcs/VBAProcsToManageOutlookContactsFromAccess.htm
0
 
LVL 3

Accepted Solution

by:
humergu earned 500 total points
ID: 20399428
your code...

 For Each re In item.Recipients

re.Adress is the email adress
re.AddressEntry gets the adress entry object
re.Name is the Name (display-name) of the recipient

infos are available in
C:\Program Files\Microsoft Office\OFFICE11\1031\VBAOL11.CHM

(maybe the path is a bit different for your installation)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Learn more about how the humble email signature can be used as more than just an electronic business card. When used correctly, a signature can easily be tailored for different purposes by different departments within an organization.
Outlook Free & Paid Tools
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now