Batch output Outlook Address book content using VBA

Source: Internet
Author: User

I found that I often need to synchronize the Gmail address book with the Outlook Address Book, and often I just want to update the user information of a certain category. The outlook menu only supports exporting all address book information as CSV files. When I want to output only one category (for example, "classmate. High School"), I need to first output it as an Excel table and then filter and convert it into a CSV file.It cannot be a great time.. I decided to use VBA to solve this problem.

Outlook is one of the office components. It supports VBA automation objects, but there are few books related to it. It can only be learned through Google's own exploration. The final script is as follows:

Sub ExportVCards () dim objNS As NameSpace 'namespace Dim objcontactfolder' address book directory Dim objEntry As Variant 'oem entry Dim objContactEntry As ContactItem 'address book entry Dim count As Integer 'counter Dim CategoriesName As string' category exportFolder As String 'output directory CategoriesName = "students. middle School "ExportFolder =" e: \ temp \ contacts \ "count = 0 Set objNS = Application. getNamespace ("MAPI") 'is used to connect to the command space. This is the method Set objContactFolder = objNS to obtain the command handle when a macro is used in Outlook. getDefaultFolder (olFolderContacts) 'to the address book directory For Each objEntry In objContactFolder. items 'traverse the address book directory If Not TypeOf objEntry Is ContactItem Then If TypeOf objEntry Is DistListItem Then Debug. print "Found a distribution list, skipping" Else Debug. print "****** found a something odd *****" Debug. print "" & objEntry End If Else Set objContactEntry = objEntry If CategoriesName = objEntry. categories Then count = count + 1 path = ExportFolder & "contact" & count &". vcf "objContactEntry. saveAs path and olVCard output the entry to the directory. End If Next Set objNS = NothingEnd Sub

After the above Code, output all communication contact entries of this category to a single file, and then use the command to merge all files. The method I use is the cat command of cygwin, that is

cat contact*.vcf > all.vcf

After being imported to Gmail, use merge to integrate duplicate personnel.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.