2009-08-10 149 views
1

所有,出口本地Outlook联系人到vCard

我想写这将导出存储在Outlook中的本地PST文件以电子名片的所有联系人程序

我见过几个共享软件程序,会做,但他们似乎相当昂贵(50块钱+)

我在这里看到一个例子,但安装Outlook

如何我会去任何想法似乎更适应到Exchange Server而不是本地对这个?

回答

2

这可能适合。

Sub VCardOut() 
Dim oFolder As Object 
Dim oContact As ContactItem 
Dim sPath As String 
Dim sName As String 
Dim sVCard As String 
Dim f As Object 
Dim fs As Object 
Dim i As Integer 


    Set fs = CreateObject("Scripting.FileSystemObject") 
    Set oFolder = GetNamespace("MAPI").GetDefaultFolder(olFolderContacts) 

    sPath = "C:\Docs\" 

“问题的格式和反斜线

'' Loop through all of the items in the folder. 
    For i = 1 To oFolder.Items.Count 
     Set oContact = oFolder.Items(i) 

     sName = oContact.FullNameAndCompany & ".vcf" 

     If Trim(sName) = ".vcf" Then sName = oContact.EntryID & ".vcf" 

     Set f = fs.CreateTextFile(sPath & sName) 

     sVCard = "BEGIN:VCARD" & vbCrLf 
     sVCard = sVCard & "VERSION:2.1" & vbCrLf 

     sVCard = sVCard & "FN:" & oContact.FullName & vbCrLf 

     sVCard = sVCard & "N:" & oContact.LastName & ";" & oContact.FirstName & ";" _ 
      & oContact.MiddleName & ";" & oContact.Title & ";" & vbCrLf 

     sVCard = sVCard & "NICKNAME:" & oContact.NickName & vbCrLf 

     sVCard = sVCard & "ADR;HOME;ENCODING=QUOTED-PRINTABLE:;;" _ 
      & Replace(oContact.HomeAddress & "", vbCrLf, "=0D=0A") & ";" _ 
      & Replace(oContact.HomeAddressCity & "", vbCrLf, "=0D=0A") & ";" _ 
      & Replace(oContact.HomeAddressCountry & "", vbCrLf, "=0D=0A") & vbCrLf 

     sVCard = sVCard & "ADR;WORK;ENCODING=QUOTED-PRINTABLE:;;" _ 
      & Replace(oContact.BusinessAddress & "", vbCrLf, "=0D=0A") & ";" _ 
      & Replace(oContact.BusinessAddressCity & "", vbCrLf, "=0D=0A") & ";" _ 
      & Replace(oContact.BusinessAddressCountry & "", vbCrLf, "=0D=0A") & vbCrLf 

     sVCard = sVCard & "BDAY:" & Format(oContact.Birthday, "yyyymmdd") & vbCrLf 

     sVCard = sVCard & "EMAIL;PREF;INTERNET:" & oContact.Email1Address & vbCrLf 

     '' Repeat as necessary for each email address 
     sVCard = sVCard & "EMAIL;INTERNET:" & oContact.Email2Address & vbCrLf 

     sVCard = sVCard & "ORG:" & oContact.CompanyName & ";" & oContact.Department & vbCrLf 

     sVCard = sVCard & "TEL;CELL;VOICE:" & oContact.MobileTelephoneNumber & vbCrLf 

     sVCard = sVCard & "TEL;HOME;FAX:" & oContact.HomeFaxNumber & vbCrLf 

     sVCard = sVCard & "TEL;HOME;VOICE:" & oContact.HomeTelephoneNumber & vbCrLf 

     sVCard = sVCard & "TEL;WORK;FAX:" & oContact.BusinessFaxNumber & vbCrLf 

     sVCard = sVCard & "TEL;WORK;VOICE:" & oContact.BusinessTelephoneNumber & vbCrLf 

     sVCard = sVCard & "TITLE:" & oContact.JobTitle & vbCrLf 

     sVCard = sVCard & "URL;HOME:" & oContact.PersonalHomePage & vbCrLf 

     sVCard = sVCard & "URL;WORK:" & oContact.BusinessHomePage & vbCrLf 

     sVCard = sVCard & "REV:20090225T232716Z" & vbCrLf 
     sVCard = sVCard & "End: VCARD" 

     f.WriteLine sVCard 
     f.Close 
    Next 

End Sub 
0

这里有更多本土的方式来做到这一点在C#:

using Microsoft.Office.Interop.Outlook; 
using System; 
using System.Collections.Generic; 
using System.Text; 

namespace ExportOutlookContacts 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 

      Items OutlookItems; 
      Application outlookObj; 
      MAPIFolder Folder_Contacts; 

      outlookObj = new Application(); 
      Folder_Contacts = outlookObj.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts); 
      OutlookItems = Folder_Contacts.Items; 

      for (int i = 0; i < OutlookItems.Count; i++) 
      { 
       ContactItem contact = (ContactItem)OutlookItems[i + 1]; 
       Console.WriteLine(contact.FullName); 
       // https://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.olsaveastype.aspx 
       contact.SaveAs(string.Format(@"C:\TEMP\Contacts\{0}.vcf", contact.FullName), 6); 
      } 

      Console.WriteLine("Done!"); 
      Console.ReadLine(); 
     } 
    } 
} 

注:您需要添加引用到Microsoft。 Office.Interop.Outlook

这将导出所有联系人在当前的Outlook配置文件中添加多个.VCF文件。

BTW您可以在一个组合所有VCF文件:

copy /B *.vcf CombinedContacts.vcf 

这样你就可以很容易地导入此文件Gmail或IPhone。