惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

M
MIT News - Artificial intelligence
有赞技术团队
有赞技术团队
S
Schneier on Security
aimingoo的专栏
aimingoo的专栏
T
Troy Hunt's Blog
U
Unit 42
Hacker News - Newest:
Hacker News - Newest: "LLM"
V2EX - 技术
V2EX - 技术
T
The Blog of Author Tim Ferriss
V
Visual Studio Blog
H
Heimdal Security Blog
H
Hacker News: Front Page
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Cloudbric
Cloudbric
Google DeepMind News
Google DeepMind News
C
Cisco Blogs
The Cloudflare Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
MyScale Blog
MyScale Blog
F
Fortinet All Blogs
N
News | PayPal Newsroom
Attack and Defense Labs
Attack and Defense Labs
D
DataBreaches.Net
N
News and Events Feed by Topic
Security Archives - TechRepublic
Security Archives - TechRepublic
Forbes - Security
Forbes - Security
Simon Willison's Weblog
Simon Willison's Weblog
F
Full Disclosure
The Register - Security
The Register - Security
L
LINUX DO - 热门话题
Webroot Blog
Webroot Blog
Google Online Security Blog
Google Online Security Blog
AI
AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
I
Intezer
S
Security Affairs
阮一峰的网络日志
阮一峰的网络日志
K
Kaspersky official blog
云风的 BLOG
云风的 BLOG
博客园 - 叶小钗
T
Threatpost
Spread Privacy
Spread Privacy
小众软件
小众软件
AWS News Blog
AWS News Blog
S
Secure Thoughts
S
Security @ Cisco Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
J
Java Code Geeks

博客园 - yankchina

[C++]VisualC++2010Express英文版试用手记 [C++]C++学习的一些建议 [Soft]物联网时代中的编程语言 - yankchina - 博客园 [Web]Web在线地图API试用笔记 [Python]命令行解析器Argparse的试用手册 [PHP]PHP技术基础 [Blog]将syntaxhighlight与LatexMathML本地化 [Soft]软件技术的两个趋势 [Soft]RAD的代价 [Python]快速解析数据库视图XML配置获取数据库字段说明 试用交互原型设计软件Axure RP Pro 4 云计算零接触 Camtasia Studio 7 试用笔记 文档整理经验谈 命令行调用Lame批量压缩MP3 [C++]千万不要碰VisualStudio - yankchina - 博客园 CSS 使用经验备忘 用Compare It! 4 比较Word Wiki 比较
用VBA批量输出Outlook通讯录内容 - yankchina - 博客园
yankchina · 2010-05-14 · via 博客园 - yankchina

我发现自己经常要将Gmail通讯录与Outlook通讯录进行同步操作,而往往我只是要更新某个类别的用户信息。Outlook菜单只支持全部导出通讯录信息为csv文件。而当我想要只输出某一类别(如"同学.高中"时)则要先输出为Excel表格,再筛选转换成csv文件。绝不能这样耗费大好时光。我决意用VBA来解决这个问题。

Outlook是Office组件之一,其支持VBA自动化对象,但相关书籍较少,只能通过Google与自己摸索来学习,最终脚本如下:

Sub ExportVCards()

    Dim objNS As NameSpace '命名空间
    Dim objContactFolder   '通讯录目录
    Dim objEntry As Variant 'OEM条目
    Dim objContactEntry As ContactItem '通讯录条目
    Dim count As Integer '计数器
    Dim CategoriesName As String '类别名称  
    Dim ExportFolder As String '输出目录  
    CategoriesName = "同学.中学"
    ExportFolder = "e:\\temp\\contacts\\"
    
    count = 0
    
    Set objNS = Application.GetNamespace("MAPI") '连接到命令空间中,这是直接在Outlook中运用宏时获取命令句柄的方法
    Set objContactFolder = objNS.GetDefaultFolder(olFolderContacts) '转到通讯录目录中
    
    For Each objEntry In objContactFolder.Items   '遍历通讯录目录
        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, olVCard '将该条目输出到目录中
            End If
        End If
    Next
    Set objNS = Nothing
End Sub

经过上述代码后,将该类别所有的通信联系人条目输出到单个文件中,再用命令将所有文件合并起来,我采用的方法是 Cygwin 的Cat 命令,即

cat contact*.vcf > all.vcf

这样导入到Gmail后,再用Merge整合重复的人员即可