1.

Solve : Outlook, generating contact list?

Answer»

I recently upgraded my xp system to windows 7 and I have backed up my old email files but I forgot to back up my Contact list. Is there any way in outlook to generate a contact list from my sent emails?Open Outlook / Sent  / open a send email / right-click the recipient / choose "Add to contacts"

Alan <><  Quote from: ale52 on December 29, 2009, 01:22:39 PM

Open Outlook / Sent  / open a send email / right-click the recipient / choose "Add to contacts"
Unfortunately, this is a one-at-a-time procedure. I don't BELIEVE there are any batch techniques that can be applied here to speed up the process.try some of the VBA on the following SITE:

http://www.outlookcode.com/d/code/autoaddrecip.htm

How?

Well, that's a good question; the site addresses adding contacts as you send new e-mails, not iterating through your sent mail.

however- Office, including outlook, includes a rich programming environment known as VBA. Lucky for you I'm pretty good with Visual Basic 6 and this problem caught my fancy.

On the other hand: I was unable to properly test it; since my sent items folder was empty. I tested the basic logic on my other outlook folders, and it seems to work. NOTE that I've only tested this with Outlook 2003.



1. Select TOOLS->Macro->Visual Basic Editor. The Visual Basic Editor Window appears.

2.on the Visual Basic Editor Menu, Select Insert->Module.

Delete anything that is present in the new module, and paste the following:


Code: [Select]Option Explicit


Sub AddSentItemsToContacts()
    Dim ObjNS As Outlook.NameSpace
    Dim ColSentItems As Folders, LoopThrough As MAPIFolder
    Set ObjNS = Application.GetNamespace("MAPI")
'    Set ColSentItems = ObjNS.GetDefaultFolder(olFolderSentMail).Folders
'Set ColSentItems = .Folders
 IterateFolders ObjNS.GetDefaultFolder(olFolderSentMail)
'    For Each LoopThrough In ColSentItems
'        IterateFolders LoopThrough
'    Next
End Sub
Private Sub IterateFolders(LoopIn As MAPIFolder)
 Dim LoopFolder As MAPIFolder
 Dim LoopMail As Outlook.MailItem
 For Each LoopFolder In LoopIn.Folders
    IterateFolders LoopFolder
   
 
 Next
 For Each LoopMail In LoopIn.Items
    AddRecipToContacts LoopMail
 
 Next
End Sub
Sub AddRecipToContacts(objMail As Outlook.MailItem)
    Dim strFind As String
    Dim strAddress As String
    Dim ObjNS As Outlook.NameSpace
    Dim colContacts As Outlook.Items
    Dim objContact As Outlook.ContactItem
    Dim objRecip As Outlook.Recipient
    Dim i As Integer
    On Error RESUME Next

    ' get Contacts folder and its Items collection
    Set ObjNS = Application.GetNamespace("MAPI")
    Set colContacts = _
      ObjNS.GetDefaultFolder(olFolderContacts).Items
   
    ' process message recipients
    For Each objRecip In objMail.Recipients
        ' check to see if the recip is already in Contacts
        strAddress = AddQuote(objRecip.Address)
        For i = 1 To 3
            strFind = "[Email" & i & "Address] = " & _
                      strAddress
            Set objContact = colContacts.Find(strFind)
            If Not objContact Is Nothing Then
                Exit For
            End If
        Next

        ' if not, add it
        If objContact Is Nothing Then
            Set objContact = _
              Application.CreateItem(olContactItem)
            With objContact
                .FullName = objRecip.Name
                .Email1Address = strAddress
                .Save
            End With
        End If
        Set objContact = Nothing
    Next

    Set ObjNS = Nothing
    Set objContact = Nothing
    Set colContacts = Nothing
End Sub

' helper function - put in any module
Function AddQuote(MyText) As String
    AddQuote = Chr(34) & MyText & Chr(34)
End Function

Select File->Save.

Return to the outlook window.

Select Tools->Macro: AddSentItemsToContacts

If we're lucky, it adds all the e-mail addresses it finds in sent emails as contacts. If an Error occurs, the error will be highlighted in the Visual Basic editor; let me know the error message and what line it happens on, and I'll try to fix it.


Quote from: soybean on December 29, 2009, 06:04:12 PM
Unfortunately, this is a one-at-a-time procedure. I don't believe there are any batch techniques that can be applied here to speed up the process.

Yeah, I know.   But it's the best I could come up with in the time I had.

Alan <><  I hope mine works  Yours seems like a pretty good way to do it.  I hope it works too.

Alan <><


Discussion

No Comment Found