Question : Can anyone tell me what this Outlook code does...

Hi,

Can anyone tell me what this Outlook code does...
I know i have used this a lot of times but have not recorded the action in the code...

Regards
Sharath
Code Snippet:
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:
Sub ProcessMessages1()
    Dim olkMsg As Outlook.MailItem, _
        olkRecipient As Outlook.Recipient
    For Each olkMsg In Application.ActiveExplorer.Selection
        If olkMsg.Class = olMail Then
            For Each olkRecipient In olkMsg.Recipients
                CreateContact1 olkRecipient.Name, olkRecipient.Address
            Next
        End If
    Next
    Set olkMsg = Nothing
End Sub
 
Sub CreateContact1(strName As String, strAddress As String)
    Dim olkFolder As Outlook.MAPIFolder, _
        olkContact As Outlook.ContactItem
    Set olkFolder = Session.GetDefaultFolder(olFolderContacts)
    Set olkContact = olkFolder.Items.Find("[Email1Address] = '" & strAddress & "'")
    If IsNothing(olkContact) Then
        Set olkContact = Application.CreateItem(olContactItem)
        With olkContact
            .FullName = strName
            .Email1Address = strAddress
            .Save
        End With
    End If
    Set olkContact = Nothing
    Set olkFolder = Nothing
End Sub

Answer : Can anyone tell me what this Outlook code does...

To amplify I have modified ProcessMessages1 below to add the sender to the contacts folder in the same way as the recipients.

The code addition to achieve this is:

            CreateContact1 olkMsg.SenderName, olkMsg.sendereMailAddress

All other subs should be unchanged.

Chris
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
Sub ProcessMessages1()
    Dim olkMsg As Outlook.mailitem, _
        olkRecipient As Outlook.Recipient
    For Each olkMsg In Application.ActiveExplorer.Selection
        If olkMsg.Class = olMail Then
            For Each olkRecipient In olkMsg.Recipients
                CreateContact1 olkRecipient.Name, olkRecipient.Address
            Next
            CreateContact1 olkMsg.SenderName, olkMsg.sendereMailAddress
        End If
    Next
    Set olkMsg = Nothing
End Sub
Random Solutions  
 
programming4us programming4us