How to Create Macro in Visual Basic to add Contacts from Personal Folder

Status
Not open for further replies.

mickash

Member
Outlook version
Email Account
POP3
:confused:Help! My contact list on a prior system was deleted. I have imported all of my emails into my new Microsoft Outlook 2003 but going through all the emails individually to add contacts is horrible when you have thousands of emails. Does anyone have the micro basic code to set up a macro to add contacts from the personal favorite folder?

i.e. click on a message, right address, click on add to contact list, then click on save and close (when outlook creates contact)?

I would really appreciate all the help I can get. Visual Basic looks like greek!
 

Forum Admin

Senior Member
there are addins you could use - at least i think they might work as you need to use something you can run on mail in your folders.

Here is a code sample that adds them when replying - http://www.outlookcode.com/d/code/autoaddrecip.htm - you'd need to change it to do it on all messages. (I'll check around and see if anyone has sample code that better meets your needs.)

We have a long list of tools here: http://www.slipstick.com/contacts/addauto.asp - but I'm not sure if any can go through folders and create contacts. (the custom action sample would be prefer using run rules now but it need compiled.)
 

Forum Admin

Senior Member
Here you go - compliments of at http://www.slovaktech.com



The macro will work in any selected folder on all selected items in that folder.



Any selected mail items will be harvested. Because I wanted to only use the OOM and you didn’t say if this was 2007 or later only, I didn’t use the MAPI properties for SentOnBehalfOf* other than for name. So the email addresses may not be accurate (for example mails sent to mailing lists will show the list address, not the actual sender's address.)



If this were 2007 or later code only I’d use PropertyAccessor to pick up the PR_SENT_REPRESENTING_ADDRTYPE and PR_SENT_REPRESENTING_EMAIL_ADDRESS properties instead of using SenderEmailAddress and SenderEmailAddressType.



A text file of this code is here: http://www.slipstick.com/contacts/_oft/save-addresses-to-contacts.txt


Code:

 
 
' The AddAddressesToContacts procedure can go in any Module
 
 
' Select the mail folder and any items to add to contacts, then run the macro
 
 
Public Sub AddAddressesToContacts()
 
 
Dim folContacts As Outlook.MAPIFolder
 
 
Dim colItems As Outlook.Items
 
 
Dim oContact As Outlook.ContactItem
 
 
Dim oMail As Outlook.MailItem
 
 
Dim obj As Object
 
 
Dim oNS As Outlook.NameSpace

 
 
Dim response As VbMsgBoxResult

 
 
Dim bContinue As Boolean

 
 
Dim sSenderName As String

 
 
On Error Resume Next

 
 
Set oNS = Application.GetNamespace("MAPI")
 
 
Set folContacts = oNS.GetDefaultFolder(olFolderContacts)
 
 
Set colItems = folContacts.Items

 
 
For Each obj In Application.ActiveExplorer.Selection
 
 
If obj.Class = olMail Then
 
 
Set oContact = Nothing

 
 
bContinue = True
 
 
sSenderName = ""

 
 
Set oMail = obj

 
 
sSenderName = oMail.SentOnBehalfOfName
 
 
If sSenderName = "" Then
 
 
sSenderName = oMail.SenderName
 
 
End If

 
 
Set oContact = colItems.Find("[FullName] = '" & sSenderName & "'")

 
 
If Not (oContact Is Nothing) Then
 
 
response = MsgBox("This appears to be an existing contact: " & sSenderName & ". Do you still want to add it as a new conact?", vbQuestion + vbYesNo, "Contact Adder")
 
 
If response = vbNo Then
 
 
bContinue = False
 
 
End If
 
 
End If

 
 
If bContinue Then
 
 
Set oContact = colItems.Add(olContactItem)
 
 
With oContact
 
 
> Body = oMail.Subject

 
 
> Email1Address = oMail.SenderEmailAddress
 
 
> Email1DisplayName = sSenderName
 
 
> Email1AddressType = oMail.SenderEmailType

 
 
> FullName = oMail.SenderName

 
 
> Save
 
 
End With
 
 
End If
 
 
End If
 
 
Next

 
 
Set folContacts = Nothing
 
 
Set colItems = Nothing
 
 
Set oContact = Nothing
 
 
Set oMail = Nothing
 
 
Set obj = Nothing
 
 
Set oNS = Nothing
 
 
End Sub
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
A Outlook macro to create search folder with mail categories as criteria Outlook VBA and Custom Forms 3
Tanja Östrand Outlook 2016 - Create Macro button to add text in Subject Outlook VBA and Custom Forms 1
B Macro To Create Rule To Export From Certain Folder Email Information in one workbook multiple sheets Outlook VBA and Custom Forms 0
A Create Macro for hyperlink(email) in message body Outlook VBA and Custom Forms 9
L Macro Create Contact and Save Using Outlook 2
L Macro Create Contact and Save Using Outlook 8
S Macro to create notification emails Using Outlook 1
N Macro to create task Using Outlook 1
S Macro to create a new folder with subject line as the folder name Using Outlook 2
P Please Help me Create a Macro ! Using Outlook 2
S Macro to create a new contact, 2 appointments, and a task Using Outlook 1
C Outlook VBA - Create Macro Move Contact field Item to Another Using Outlook 1
R How do I create a macro to put text in certain emails? Outlook VBA and Custom Forms 1
D Create a macro in Outlook to run a rule Outlook VBA and Custom Forms 32
N How Can I create an Outlook Macro to import calendar? Outlook VBA and Custom Forms 1
P How do I create a macro to add contacts from email messages? Outlook VBA and Custom Forms 1
J Macro to create folder in PST file Outlook VBA and Custom Forms 4
G Macro: Create New Message and Auto populate To Field Outlook VBA and Custom Forms 5
S How to create a macro to insert a signature in Outlook 2007 Outlook VBA and Custom Forms 1
Chiba Create an appointment for all the members Outlook VBA and Custom Forms 1
S Create a clickable custom column field Outlook VBA and Custom Forms 0
O Create a custom contact form - questions before messing things up... Outlook VBA and Custom Forms 4
C Can't create Outlook data file Outlook Wishlist 0
L automaticaly create a teams meeting with a sync Using Outlook 0
D Can Exchange Admin Center create a pst for users email/contacts/calendar? Exchange Server Administration 0
S Create A Search Folder That Looks For Message Class? Outlook VBA and Custom Forms 0
F How to create phone number as links in notes of Contacts Using Outlook 2
Nessa Can't create new appointment Using Outlook 1
A Create date folder and move messages daily Outlook VBA and Custom Forms 1
C Create new Message with shared contacts & BCC'ing recipients Outlook VBA and Custom Forms 0
O Multiple email accounts - hesitate to create a new profile Using Outlook 3
G Can't create Folder Groups in Outlook 2013 Using Outlook 0
N Outlook rules don't create a copy for bcc'ed emails Using Outlook 3
F Delete/create/reset Exchange mailbox on Outlook.com Using Outlook.com accounts in Outlook 3
R Can not create folder to store specific emails in in Outlook for Mac Using Outlook 1
W Create Search Folder excluding Specific Email Addresses Using Outlook 5
K VBA BeforeItemMove event create rule to always move to its folder. Outlook VBA and Custom Forms 4
JackBlack What tools do you use to create the signature for email? Using Outlook 3
Rupert Dragwater How to create a new email with @outlook.com Using Outlook.com accounts in Outlook 32
F Should a new email account also create new contacts Using Outlook 2
D create an html table in outlook custom form 2010 using vba in MsAccess Outlook VBA and Custom Forms 7
R Outlook add-in to create new contact from an email. Using Outlook 0
Q Script to create a pst file for Archiving Using Outlook 1
Jennifer Murphy Can I create a Rule with Or'd conditions? Using Outlook 1
D Outlook macros to create meeting on shared calendar Outlook VBA and Custom Forms 10
G How do I create a custom pick list in VB for an outlook automated email? Outlook VBA and Custom Forms 1
L Create Custom Form Using Outlook 0
Diane Poremsky Create a Task when a Message is Flagged New Slipstick.com Articles 0
Stilgar Relsik Create a rule to copy text from an email and paste it in the subject line. Using Outlook 1
Diane Poremsky Create a custom field for Outlook messages New Slipstick.com Articles 0
Similar threads


















































Top