Macro to auto-fill "Company" field in VCard based on email domain?

  • Thread starter Andrew Schulman
  • Start date
A

Andrew Schulman

Hi -- I'm not sure if this is possible or how difficult it is, but lately,
I'm auto-adding Contacts to Outlook from a variety of sources (LinkedIn,
etc.) and most of the time, these new VCards contain the person's email
address, but not necessarily their Company. If there is one company in
particular that I'm adding a lot of people from, is there a macro that can
search the email addresses of my contacts and if they have a specific domain,
auto-fill their company name? (i.e. I'm just looking to auto-fill the
company for people with one specific email domain, not for all my contacts.)

Any help/wisdom/guidance would be greatly appreciated.

Thanks,

Andrew
 
A

Andrew Schulman

Thanks for the response, JP.

It would help if I could sort by "email domain," but that's not a standard
field. So, if I created that as a user-defined field, and then was able to
auto-populate it based on what was after the ampersand in the email address
field, then step 2 could be the one you pointed out below. Any thoughts on
how to auto-populate one field based on info from another? Is that a
standard/simple macro operation?

Thanks again,

Andrew
 
J

JP

Didn't think I'd say this, but maybe a macro to loop through your
Contacts folder, parse the email address of the contact and, if it
meets the criteria, fill in the Company Name, might be easier.

Do you have any macro writing experience?

--JP
 
A

Andrew Schulman

Yes, that sounds exactly like what I need. Unfortunately, I don't have any
experience in VBA or writing macros. I'm guessing it's not something I could
do without a fair amount of time to dedicate to it, right?
 
J

JP

I found some sample code here that should work. All you have to do is
change "somewhere.com" to the domain you are looking for, and change
"My Company" to the company name you want for those contacts at the
domain. It loops through all of your contacts and if it finds an email
address domain matching the one you specify, it updates the Company
Name field accordingly.


(From http://support.microsoft.com/kb/195699)

Sub UpdateContactCompany()
Dim ol As Outlook.Application
Dim olns As Outlook.Namespace
Dim oConItems As Outlook.Items
Dim iNumItems As Long
Dim lCount As Long

Set ol = New Outlook.Application
Set olns = ol.GetNamespace("MAPI")
Set oConItems = olns.GetDefaultFolder(olFolderContacts).Items
iNumItems = oConItems.Count
For lCount = 1 to iNumItems
Set oCurItem = oConItems.Item(lCount)

If Instr(oCurItem.Email1Address, "somewhere.com") > 0 Then
oCurItem.CompanyName = "My Company"
oCurItem.Close olSave
End If
Next lCount

Set oConItems = Nothing
Set olns = Nothing
Set ol = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top