A user decided the BCM was overkill for his needs and wanted to move his 5000 Business Contacts into Outlook Contacts before upgrading to Office 365. The only issue was keeping the contact associated with the Account name it was assigned to in BCM. The Company name field was suitable, but he needed to update 5000 contacts, which would take "forever".
This macro adds the Account's display name to the company field (only if the company name field is empty). It's not the fastest macro in the world (it takes several minutes to check 5000 contacts), but it is faster than other methods. After it's finished, Select All (Ctrl+A) and drag the contacts from Business Contacts to Outlook's Contacts folder.
Public Sub ChangeFileAs() Dim olApp As Outlook.Application Dim objNS As Outlook.NameSpace Dim olFolders As Outlook.Folders Dim bcmRootFolder As Outlook.Folder Dim bcmContactsFldr As Outlook.Folder Dim objItems As Outlook.Items Dim obj As Object Dim objContact As Outlook.ContactItem Set olApp = CreateObject("Outlook.Application") Set objNS = olApp.GetNamespace("MAPI") Set olFolders = objNS.Session.Folders Set bcmRootFolder = olFolders("Business Contact Manager") Set bcmContactsFldr = bcmRootFolder.Folders("Business Contacts") Set objItems = bcmContactsFldr.Items For Each obj In objItems Set objContact = obj With objContact If .CompanyName = "" Then .CompanyName = .UserProperties("ParentDisplayName") .Save End If End With Err.Clear Next Set bcmRootFolder = Nothing Set olFolders = Nothing Set objNS = Nothing Set olApp = Nothing End Sub
How to use macros
First: You will need macro security set to low during testing.
To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.
After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.
Open the VBA Editor by pressing Alt+F11 on your keyboard.
To put the code in a module:
- Right click on Project1 and choose Insert > Module
- Copy and paste the macro into the new module.
More information as well as screenshots are at How to use the VBA Editor
More Information
Business Contacts - Outlook Developer Reference
Don't suppose there is any way to modify the macro to put the company name in after the contacts have been moved is there?
Either from the 'Full Name' field or the 'Account Name' field in the user defined fields.
After copying the accounts over, the company name is in the username field and I can't get it to copy over. I have over 7,000 companies.
you can move (or copy) values from the user fields - you'd use an if statement to check the fields and move them. The macro at https://www.slipstick.com/outlook/contacts/swap-first-and-last-name-fields/ has an example using the user fields. (This is a better sample than the earlier one.)
Not to worry, I have solved it. It should have been this:
If .CompanyName = "" Then
Let .CompanyName = .FullName
If .FullName "" Then
Let .FullName = ""
Thank you for all your help.
Thank for sharing your knowledge! One question on the macro to copy the Company to the Account field in BCM 2010. Mine is failing at the code line: Set bcmContactsFldr = bcmRootFolder.Folders("Business Contacts"). I am getting the 'Object not found'. I did find an msdn article about Public folders not being found when using Exchange Online and tried to extrapolate from there. So the question is: Is the error related to Exchange or related to where my "Business Contacts" folders resides (AppData\Local\Microsoft\Business Contact Manager)? Thanks again!
That wouldn't have anything to do with public folders. The root folder refers to the BCM Business Contacts and the macro runs on the contacts in BCM, adding the Account name to the company name if the company name field is empty.