Copy Outlook Shared Contacts to My Contacts via Excel VBA

tpthatsme

New Member
Joined
Jun 2, 2016
Messages
17
Scenario: Another user on Microsoft Exchange has shared an Outlook Contact folder with me and I would like to create an Excel VBA macro to copy the content of that folder to another "local" folder in my Outlook Contacts.

I have written a VBA solution that is very close to what I want but it copies the contents from my default folder to a subfolder.

VBA Code:
Sub CopyContacts()

Dim ol_ContactItem As Outlook.ContactItem
Dim ol_Name As Outlook.Namespace
Dim ol_Folder As Outlook.Folder
Dim ol_SharedFolder As Outlook.Folder
Dim ol_Item As Object
Dim ol_Recipient As Outlook.Recipient

Set ol_Name = Outlook.GetNamespace("MAPI")
Set ol_Recipient = ol_Name.CreateRecipient("John Doe")
ol_Recipient.Resolve

Set ol_Folder = ol_Name.GetDefaultFolder(olFolderContacts)
Set ol_SharedFolder = ol_Name.GetSharedDefaultFolder(ol_Recipient, olFolderContacts)

    For Each ol_Item In ol_Folder.Items

        If ol_Item.Class = olContact Then

        Set ol_ContactItem = ol_Item.Copy
        ol_ContactItem.Move ol_Folder.Folders("Another_Folder")

        End If

    Next

End Sub

In this example I think I have the right syntax for identifying the Recipient, but I can't seem to get the right syntax to copy the content to my folder.
When I use the following in my For statement, it fails.
Code:
For Each ol_Item In ol_SharedFolder.Items
Anyone have any suggestions?
1656333931006.png
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,223,275
Messages
6,171,127
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top