regarding the Create Contacts From Messages code

Status
Not open for further replies.

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
This is where the contact form is opened:
Set oContact = colItems.Add(olContactItem)

So, you just need to change that to use a template:
Set oContact = Application.CreateItemFromTemplate("C:\path\to\template.oft")

Or if you are using a published form, you need to use items.add:
Set Items = Session.GetDefaultFolder(olFolderContacts).Items
Set oContact= Items.Add("ipm.contact.myform")
 

mr_malkovich

Senior Member
Outlook version
Email Account
Exchange Server
Thanks for your reply Diane. And sorry for clogging up your forum the last day or two. Just having a minor technical meltdown here.
The form is located in the Personal Forms Library. It's 112607.fdm. How should I modify that?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
When it's published , it should have a name (message class) like ipm.contacts.something. This is the name you'll use with items.add.

forms.png
 

mr_malkovich

Senior Member
Outlook version
Email Account
Exchange Server
Hi, I altered your code per your instructions then ran it on a test inbox sub-folder of three messages. The code is below, with the portion I altered in bold. If the contact forms were created, I cannot find them. The three messages already have corresponding contact forms in the Contacts folder. Is that why the contact forms may not have been created?



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 contact?", vbQuestion + vbYesNo, "Contact Adder")
If response = vbNo Then
bContinue = False
End If
End If

If bContinue Then
Set oContact = Application.CreateItemFromTemplate("IPM.contact.112607")
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
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
No, you should have either created duplicates or received the duplicate contact exists message, if that option is enabled. Try adding .display above save and see if a form pops up. (It didn't here, will review the code next)
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
That was easy to fix - change the create line to this:
Set oContact = folContacts.Items.Add("IPM.contact.112607")

When you use published forms, you need to use items.add not createfromtemplate.
 

mr_malkovich

Senior Member
Outlook version
Email Account
Exchange Server
Excellent, thank you. Can this code be set so that the new contacts are created in a folder other than Contacts? That way I can clean up the contacts a bit before I throw them in general population.

Also, has anyone modified this code to do things like search signatures for info to automatically input into the contact form too?

Thanks again. You might have added a couple of years of free time to my life.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
This sets the folder: Set folContacts = oNS.GetDefaultFolder(olFolderContacts)
To use a subfolder of contacts, use Set folContacts = oNS.GetDefaultFolder(olFolderContacts).Folders("folder name")
More information here - Working with VBA and non-default Outlook Folders

I don't have any code samples that look for the signatures - the problem would be in formatting. The code samples I have use regex to look for specific patterns and everyone uses different patterns for personal information. There are add-ins that do it - but because they are com add-ins, they can do a lot more things, faster, which makes searching for all of the common (and uncommon) address and phone formats easier as well as do a better job of identifying what is a signature when there are multiple signatures in a message (ie, in a long thread) or a disclaimer tacked on the end.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
Rupert Dragwater Several questions regarding Outlook 2013 Using Outlook 9
M regarding legacy contact cards Using Outlook 2
G PROBLEM REGARDING OUTLOOK STORAGE LANGUAGES Using Outlook 4
D a general question regarding data files Using Outlook 3
S Question regarding contact links Exchange Server Administration 37
T Regarding Outlook addin Outlook VBA and Custom Forms 1
J How to create a drop down user defined field that will appear on an inbox view Outlook VBA and Custom Forms 8
Commodore Any way to create "from-only" account on Outlook 2021? Using Outlook 1
L Capture email addresses and create a comma separated list Outlook VBA and Custom Forms 5
N Can't create NEW GROUP and add/remove a member from existing Group in Outlook Using Outlook 1
NVDon Create new Move To Folder list Outlook VBA and Custom Forms 0
C Create Meeting With Custom Form Outlook VBA and Custom Forms 2
D Create advanced search (email) via VBA with LONG QUERY (>1024 char) Outlook VBA and Custom Forms 2
G Create ordinal numbers for birthday Outlook VBA and Custom Forms 2
O Outlook 365 - How to create / copy a new contact from an existing one? Using Outlook 5
D Create new email from the received Email Body with attachment Outlook VBA and Custom Forms 10
A How to create fixed signatures for aliases that process through GMAIL? Outlook VBA and Custom Forms 0
P Can I create a Rule that sends me an email when I get a Task? Using Outlook 2
M How create a Rule to filter sender's email with more that one @ sign Using Outlook 1
B Can I create a local PST file for SPAM on a drive that is usually disconnected? Using Outlook 3
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
A Outlook macro to create search folder with mail categories as criteria Outlook VBA and Custom Forms 3
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
Tanja Östrand Outlook 2016 - Create Macro button to add text in Subject Outlook VBA and Custom Forms 1
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

Similar threads

Top