匯出Outlook裡的全球通訊錄到Excel

2022-02-10 18:59:50 字數 4313 閱讀 1755

最近整理硬碟檔案,發現乙個outlook裡的全球通訊錄到excel的**,但不知道這個檔案是什麼時候下的了,謹向原作者致敬。

注意:1、這個**是寫在excel的模組裡的。

2、通訊錄中聯絡人個數多的話,可能時間有點長

const cdoaddresslistgal = 0

const cdouser = 0

const cdoremoteuser = 6

#const earlybind = true

'requires excel 2000 as it uses array

'a reference must be set to the cdo 1.21 library for early binding

'the file is cdo.dll

dim x as variant, cdolist as variant, titlelist as variant, cdoitem as variant

dim numx as long, arraydump as long, i as long, v as long, u as long

range("a1:r1").value2 = array("global name", "given name", "surname", "email address", "logon", "title field", "telephone", "mobile", "fax", "csg/group", "department", "site", "address", "location", "state ", "country field", "assistant name", "assistant phone")

#if earlybind then

dim objsession as mapi.session, ofolder as mapi.addresslist, omessage as mapi.addressentry

set objsession = new mapi.session

cdolist = array(cdopr_display_name, cdopr_given_name, cdopr_surname, 972947486, cdopr_account, _

cdopr_title, cdopr_office_telephone_number, cdopr_mobile_telephone_number, cdopr_primary_fax_number, _

cdopr_company_name, cdopr_department_name, 974716958, cdopr_street_address, _

cdopr_locality, cdopr_state_or_province, cdopr_country, _

cdopr_assistant, cdopr_assistant_telephone_number)

#else

dim objsession as object, ofolder as object, omessage as object

set objsession = createobject("mapi.session")

cdolist = array(805371934, 973471774, 974192670, 972947486, 973078558, 974585886, _

973602846, 974913566, 975372318, 974520350, 974651422, 974716958, 975765534, _

975634462, 975699998, 975568926, 976224286, 976093214)

#end if

with objsession

.logon , , false, false

set ofolder = .getaddresslist(cdoaddresslistgal)

end with

titlelist = array("gal name", "given name", "surname", "email address", "logon", "title field", _

"telephone", "mobile", "fax", "csg/group", "department", "site", "address", "location", "state ", _

"country field", "assistant name", "assistant phone")

'grab 10 records in one hit before writing to sheet

'2000 would be better but excel skips records

arraydump = 10

cells.clear

'add titles

with range("a1").resize(1, ubound(titlelist) + 1)

.formula = titlelist

.horizontalalignment = xlcenter

.interior.colorindex = 35

.font.bold = true

.font.size = 12

end with

userform1.show vbmodeless

redim x(1 to arraydump, 1 to ubound(cdolist) + 1)

on error resume next

'some fields may not exist

for each omessage in ofolder.addressentries

select case omessage.displaytype

case cdouser, cdoremoteuser

i = i + 1

'reset variant array every after each group of records

if i mod (arraydump + 1) = 0 then

if numx * arraydump + i > 65535 then

msgbox "gal exceeds 65535 entries - extraction stopped ", vbcritical + vbokonly

goto fastexit

end if

numx = numx + 1

range("a2").offset((numx - 1) * arraydump, 0).resize(arraydump, ubound(cdolist) + 1) = x

redim x(1 to arraydump, 1 to ubound(cdolist) + 1)

i = 1

end if

'display status to user

if i mod arraydump = 0 then

userform1.labelprogress.width = (i + u + numx * arraydump) / ofolder.addressentries.count * userform1.frameprogress.width

userform1.labelsheetnum = format((i + u + numx * arraydump) / ofolder.addressentries.count, "percent")

doevents

end if

v = 0

' add detail to each address

for each cdoitem in cdolist

v = v + 1

x(i, v) = omessage.fields(cdoitem)

next

case else

u = u + 1

end select

next

'dump remaining entries

range("a2").offset(numx * arraydump, 0).resize(arraydump, ubound(cdolist) + 1) = x

'cleanup

fastexit:

unload userform1

activesheet.usedrange.entirerow.wraptext = false

activesheet.usedrange.autofilter

columns("a:r").autofit

set ofolder = nothing

set objsession = nothing

end sub

EXCHANGE故障處理之全球通訊簿更新

問題描述 客戶致電反饋原來某海外使用者通過聯絡人方式存在exchange通訊簿裡面,現在那個海外使用者到中國任職,此時exchange管理員刪除聯絡人,建立郵箱賬戶。建立完成後,管理員從通訊簿找到郵箱進行傳送失敗的,系統反饋沒有指定的郵箱。1.在outlook中嘗試重新繫在通訊簿,問題依舊。2.更新...

全球通漲對中國的影響

全球通漲對中國的影響 筆者在 1 2 中早就討論過美圓過剩產生的全球性通貨膨脹。筆者在今年初提出中國 開始拋售美國國債,作為2006年國際關係的要素之一。後來發現中國 實際上是繼續買進美國國債為主,而日本似乎開始拋售美國國債。3 中國 沒有採取從貶值中的美圓脫身的做法。似乎還有支撐美國經濟的意圖。這...

開發全球通用應用程式的最佳做法

開發全球通用應用程式的最佳做法 本節描述在開發全球通用的應用程式時應遵循的最佳做法。全球化最佳做法 在內部使應用程式 成為 unicode。使用 system.globalization 命名空間提供的區域性識別類來操作和格式化資料。在適當的情況下,使用 system.globalization.c...