Advertisement
gn4711

Outlook Export Contacts

Jan 17th, 2020
4,619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub ExportMultipleContactsIntoOneVCardFile()
  2.     Dim objSelection As Outlook.Selection
  3.     Dim strLocalDrive, strFolder As String
  4.     Dim i As Long
  5.     Dim objContact As Outlook.ContactItem
  6.     Dim strVCardFile As String
  7.     Dim s As String
  8.    
  9.     'Get all selected contacts
  10.    Set objSelection = Outlook.Application.ActiveExplorer.Selection
  11.  
  12.     If Not objSelection Is Nothing Then
  13.        'Save contacts in "E:\Temp Contacts\"
  14.       strLocalDrive = "c:"
  15.        strFolder = "Users\gerneu\OneDrive\Documents\vCards"
  16.        ' MkDir (strLocalDrive & "\" & strFolder & "\")
  17.  
  18.        'Save all selected contacts as separate vCards
  19.       For i = objSelection.count To 1 Step -1
  20.            If TypeName(objSelection(i)) = "ContactItem" Then
  21.               Set objContact = objSelection(i)
  22.  
  23.                 s = objContact.FullName
  24.                 s = Replace(s, "/", "-")
  25.                
  26.               strVCardFile = strLocalDrive & "\" & strFolder & "\" & s & ".vcf"
  27.               objContact.SaveAs strVCardFile, olVCard
  28.            End If
  29.        Next
  30.  
  31.        'Use cmd to merge all exported vCard files into one
  32.       Shell "cmd.exe /K" & strLocalDrive & " & CD " & strFolder & " & copy *.vcf MergedContact.vcf"
  33.     End If
  34. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement