Solved

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

Posted on 2007-11-28
2
653 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Outbound messages randomly are blank. 7 53
Network Data Opinions 8 55
Subtraction v Hex2Dec in vbscript 6 30
exchange 2007 5 36
If you don't know how to downgrade, my instructions below should be helpful.
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

713 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