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

推荐订阅源

The Register - Security
The Register - Security
云风的 BLOG
云风的 BLOG
U
Unit 42
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
D
Docker
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
S
Secure Thoughts
Hacker News: Ask HN
Hacker News: Ask HN
Vercel News
Vercel News
S
Security @ Cisco Blogs
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
I
Intezer
MongoDB | Blog
MongoDB | Blog
AI
AI
MyScale Blog
MyScale Blog
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
W
WeLiveSecurity
博客园 - 叶小钗
S
SegmentFault 最新的问题
N
News | PayPal Newsroom
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
D
DataBreaches.Net
小众软件
小众软件
Microsoft Azure Blog
Microsoft Azure Blog
Spread Privacy
Spread Privacy
H
Help Net Security
美团技术团队
博客园 - 司徒正美
T
Threat Research - Cisco Blogs
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
K
Kaspersky official blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
V
Vulnerabilities – Threatpost
TaoSecurity Blog
TaoSecurity Blog
N
Netflix TechBlog - Medium
L
Lohrmann on Cybersecurity
J
Java Code Geeks
量子位
Martin Fowler
Martin Fowler
博客园_首页

博客园 - 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整合重复的人员即可