VBA to extract contacts...

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Assuming you mean from Outlook, then yes. Do a forum search for the relevant terms such as vba export outlook contacts and I'm sure you'll find several suitable bits of code.
 
Upvote 0
Try this.

Code:
Sub GetOutlookContacts()
Dim olapp As Outlook.Application
Dim nspNameSpace As Outlook.Namespace
Dim fldContacts As Outlook.MAPIFolder
Dim objContact As Outlook.ContactItem
Dim iRow As Long
Dim sName As String
On Error Resume Next
Application.ScreenUpdating = False
Set olapp = New Outlook.Application
Set nspNameSpace = olapp.GetNamespace("MAPI")
Set fldContacts = nspNameSpace.GetDefaultFolder(olFolderContacts)
iRow = 1
Cells(iRow, 1).Resize(1, 5).Value = Array("Full Name", "First Name", "Middle Name", "Last Name", "Email Address 1")
For Each objContact In fldContacts.Items
    With objContact
        If objContact.Class = olContact Then
            iRow = iRow + 1
            Cells(iRow, 1).Value = .FullName
            Cells(iRow, 2).Value = .FirstName
            Cells(iRow, 3).Value = .MiddleName
            Cells(iRow, 4).Value = .LastName
            Cells(iRow, 5).Value = .Email1Address
            ActiveSheet.Hyperlinks.Add Cells(iRow, 5), Cells(iRow, 5).Value
        End If
    End With
Next objContact
Application.ScreenUpdating = True
Set objContact = Nothing
Set fldContacts = Nothing
Set nspNameSpace = Nothing
Set olapp = Nothing
End Sub

In the VBE, Tools > References and tick Microsoft Outlook X.X Library (X.X being your version of Outlook).
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,716
Members
452,939
Latest member
WCrawford

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