• Outlook User
  • Exchange Admin
  • Office 365
  • Outlook Developer
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
    • Common Problems
    • Outlook BCM
    • Utilities & Addins

VBA: Get All Contact Details

Slipstick Systems

› Developer › Code Samples › VBA: Get All Contact Details

Last reviewed on August 4, 2016     4 Comments

AndyZ wanted to share his macro with us:

I often need to copy a Contact's details to share with others and to put into appointments. I've used Copy2Contact in the past but it is limited and buggy, and now is very expensive since they converted to a subscription model. Anyway after updating to Windows 10 and Outlook 2016 (which you helped me with) I cast about for a way to replace Copy2Contacts "copy details" functionality. Your code helped me figure it out.

This macro displays the selected contact's details in a dialog box and copies them to the clipboard, ready to paste into other applications.
Contact details copied to clipboard.

Public Sub GetAllContactDetails()
Dim Session As Outlook.NameSpace
Dim currentExplorer As Explorer
 
Dim obj As Object
Dim DataObj As MSForms.DataObject
Dim strContactDetails As String
Set DataObj = New MSForms.DataObject
 
Set currentExplorer = Application.ActiveExplorer
Set obj = currentExplorer.Selection.Item(1)
 
If obj.Class = olContact Then
 
    With obj
 
        If .FullName <> "" Then strContactDetails = .FullName & vbCrLf
        If .JobTitle <> "" Then strContactDetails = strContactDetails & .JobTitle & vbCrLf
        If .Department <> "" Then strContactDetails = strContactDetails & .Department & vbCrLf
        If .CompanyName <> "" Then strContactDetails = strContactDetails & .CompanyName & vbCrLf
        If .MailingAddress <> "" Then strContactDetails = strContactDetails & .MailingAddress & vbCrLf
        If .BusinessAddressCountry <> "" Then strContactDetails = strContactDetails & .BusinessAddressCountry & vbCrLf
        If .BusinessTelephoneNumber <> "" Then strContactDetails = strContactDetails & "Business: " & .BusinessTelephoneNumber & vbCrLf
        If .Business2TelephoneNumber <> "" Then strContactDetails = strContactDetails & "Business 2: " & .Business2TelephoneNumber & vbCrLf
        If .CompanyMainTelephoneNumber <> "" Then strContactDetails = strContactDetails & "Company: " & .CompanyMainTelephoneNumber & vbCrLf
        If .MobileTelephoneNumber <> "" Then strContactDetails = strContactDetails & "Mobile: " & .MobileTelephoneNumber & vbCrLf
        If .Email1Address <> "" Then strContactDetails = strContactDetails & .Email1Address & vbCrLf
        If .WebPage <> "" Then strContactDetails = strContactDetails & "Company Page: " & .WebPage & vbCrLf
        If .FTPSite <> "" Then strContactDetails = strContactDetails & "LinkedIn Page: " & .FTPSite & vbCrLf
        If .Body <> "" Then strContactDetails = strContactDetails & vbCrLf
        If .Body <> "" Then strContactDetails = strContactDetails & .Body & vbCrLf
 
    MsgBox strContactDetails
 
    DataObj.SetText strContactDetails
    DataObj.PutInClipboard
 
    End With
 
Else
MsgBox "You need to select a Contact."
End If
 
Set currentExplorer = Nothing
Set obj = 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 and above, 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:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.
  3. You will need to set a reference to the Forms library in Tools, References. If its not listed, click Browse and paste C:\Windows\System32\FM20.dll or C:\Windows\FM20.dll then press Enter to add one as a Reference.
    Add the forms library as a reference

More information as well as screenshots are at How to use the VBA Editor

VBA: Get All Contact Details was last modified: August 4th, 2016 by Diane Poremsky
  • Twitter
  • Facebook
  • LinkedIn
  • Reddit
  • Print

Related Posts:

  • Copy a Contact's Mailing Address
  • Create an Appointment at the Contact's Address
  • Search for All Messages from Contact and Display in New Window
  • Print Contacts and Contact Photos

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
4 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Sabrina Defeyter (@guest_217471)
January 21, 2021 11:03 am
#217471

This works fine with saved contacts. How would I do the same for contacts in the global address book?

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Sabrina Defeyter
January 21, 2021 7:54 pm
#217473

You need to use different code. :) This macro has an example of how to read the gal using VBA
Use VBA to Create a List of Exchange GAL Members (slipstick.com)

0
0
Reply
Thong Van (@guest_200232)
July 26, 2016 12:32 am
#200232

Getting the error of - Dim DataObj As MSForms.DataObject
I using with Outlook 2013.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Thong Van
August 4, 2016 11:57 am
#200448

You need set a reference to the Forms library in Tools, References. If its not listed, add C:\Windows\System32\FM20.dll or C:\Windows\FM20.dll as a reference. (I update the instructions to include this and a screenshot).

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 28 Issue 11

Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Subscribe to Exchange Messaging Outlook






Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • WeekMonthAll
  • Adjusting Outlook's Zoom Setting in Email
  • How to Remove the Primary Account from Outlook
  • Cannot add Recipients in To, CC, BCC fields on MacOS
  • Move an Outlook Personal Folders .pst File
  • Save Sent Items in Shared Mailbox Sent Items folder
  • Create rules that apply to an entire domain
  • Outlook's Left Navigation Bar
  • Remove a password from an Outlook *.pst File
  • View Shared Calendar Category Colors
  • Use PowerShell to get a list of Distribution Group members
  • Cannot add Recipients in To, CC, BCC fields on MacOS
  • Change Appointment Reminder Sounds
  • Messages appear duplicated in message list
  • Reset the New Outlook Profile
  • Delete Old Calendar Events using VBA
  • Use PowerShell or VBA to get Outlook folder creation date
  • Outlook's Left Navigation Bar
  • Contact's Display Bug
  • Use PowerShell to get a list of Distribution Group members
  • Edit Outlook’s Attach File list
Ajax spinner

Newest Code Samples

Delete Old Calendar Events using VBA

Use PowerShell or VBA to get Outlook folder creation date

Rename Outlook Attachments

Format Images in Outlook Email

Set Outlook Online or Offline using VBScript or PowerShell

List snoozed reminders and snooze-times

Search your Contacts using PowerShell

Filter mail when you are not the only recipient

Add Contact Information to a Task

Process Mail that was Auto Forwarded by a Rule

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in Outlook for Windows.

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




Windows 10 Issues

  • iCloud, Outlook 2016, and Windows 10
  • Outlook Links Won’t Open In Windows 10
  • Outlook can’t send mail in Windows 10: error Ox800CCC13
  • Missing Outlook data files after upgrading Windows?

Outlook Top Issues

  • The Windows Store Outlook App
  • The Signature or Stationery and Fonts button doesn’t work
  • Outlook’s New Account Setup Wizard
  • Outlook 2016: No BCM
  • Exchange Account Set-up Missing in Outlook 2016

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

Outlook-tips.net Samples

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

MSDN Outlook Dev Forum

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Contact Tools

Data Entry and Updating

Duplicate Checkers

Phone Number Updates

Contact Management Tools

Diane Poremsky [Outlook MVP]

Make a donation

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Outlook Suggestion Box (UserVoice)

Slipstick Support Services

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Advertise | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2023 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment