|
呵呵,treo的联系人查找一直是我的心病,我那么多联系人难道要一个一个改拼音么!!最近对outlook的宏研究的比较多,所以,研究了1天做出了自动把firstname(名字) 的汉字自动转化为拼音加入到 lastname(姓氏)字段中去。 自己用了下,感觉还是比较好用的!当然这么好的东西,要与吹友吧的同仁一起分享了 哈哈哈哈& t' {1 v$ ^3 y; H( F$ D V( M
! Q0 z; F7 J: l4 W: K
- Z2 j) q _" z) X6 d/ p/ }4 H& `0 a7 g# j5 v& l; N" k9 |% E* a
有些生字无法转化出来,显示为“%”号,但是个人感觉不多,自己稍微改动下就好了。其实由于代码比较简单,所以只能照顾到常用字。有高手也可以把代码修改下,把拼音转化的部分增强。
0 |' Q5 F4 X% E) x- @+ j" H/ n/ V# E8 `/ X5 }7 |; v
使用环境: outlook2007[支持vba] 其他没有试过 我觉得03应该没问题7 W0 B0 Q- U) a5 m' W- E& ^7 ]
修改vba运行权限: 工具》信任中心》宏安全性》不执行宏安全性检查 {用完后再改回系统默认}
: T5 y0 [2 Z( b9 X5 m0 W( u; k3 `6 H/ Q/ ~
使用方法: 先用treo和outlook同步) j1 z4 v) f: {; ` _8 ^* D
工具》宏》vb编辑器 》新建模块 拷入代码F5运行就好了
+ @5 U: l5 \/ P# n$ O4 e9 Q. u/ C: ~# N& r% s+ D3 Q% k1 V2 f8 O- t7 A1 @) J
, ^8 i0 j3 W: D, J2 H
代码0 D" g& R. h* H) s! [ ]3 e' K
Option Explicit
4 h$ }9 b8 x2 d) H# e3 NSub setpinyin(), N- y4 N: o! c
Dim myolApp As New Outlook.Application
% t# ]% ?: J- S" S0 o Dim myNamespace As Outlook.NameSpace+ o$ |- R* e# @. w6 q6 [
Dim myAddresslists As Outlook.folder& }6 \+ R4 ?( ~! _2 w* a4 a
Dim AddressList As Outlook.AddressList
9 @7 }9 P8 r1 R" u2 @ Dim item; Y# K0 V: g. } ^
Dim temp1, temp2, v8 c* d6 H+ @. H8 O, [& O
2 k# p7 l: c1 x Set myNamespace = myolApp.GetNamespace("MAPI"); H w; N$ r U$ m- J
Set myAddresslists = myNamespace.GetDefaultFolder(olFolderContacts)6 {2 v; [' k5 S
' Set myolApp = myNamespace.GetDefaultFolder(olFolderInbox)) \* ~4 B$ z6 l3 [3 X
For Each item In myAddresslists.Items
7 i7 E, y; A" q3 F. [: t( ? 'temp1 = item.LastName & " " & item.FirstName
9 r1 b8 J% U+ x7 A6 i9 S 0 J1 A. m' e2 d. K
If item.LastName = "" Then
( l4 J" x1 y& b' Y" Q item.LastName = LCase(getpy(item.FirstName))9 w$ C2 d( o" C, { T. B9 ~* r
item.Save/ _% [% v0 Z" i; \/ V) j4 n
Debug.Print item.LastName
6 N2 d, z# ~) ]2 a( a
0 l4 f3 Y! j; `! q& N 'MsgBox item.LastName1 C; h: _8 n7 C+ [, \! N: C; E% b( K3 K
, m' _6 u2 t6 l5 `1 T) D s
End If( W3 i! e' D1 C# U1 ^" h5 G& }/ X a$ A
6 }' N0 G3 S4 n# U$ K Next
7 z C! l b: R0 t. oEnd Sub' d/ s9 `# A D, ?; j
! r/ y8 X2 M7 k
Function getpychar(char) As String
6 @, ~, h4 t1 |' A3 h On Error Resume Next" O) Z5 L% S- ?& i1 M0 b3 q2 s
Dim tmp As String, vs1 As String! t) A% [0 f3 n# v% I
! t0 p4 u+ ^# y) {# [3 |
If Asc(char) >= 0 And Asc(char) <= 127 Then
- h& B9 O& y t# }8 \, D1 k If char >= "a" And char <= "z" Then
" m+ T4 m, ?& D: b: ?( t9 a getpychar = Chr(Asc(char) - 32)5 K) M3 J% {: N5 I J& P8 z/ A
ElseIf char >= "A" And char <= "Z" Then n( y6 D" q6 G8 D; J
getpychar = char1 c1 Z9 l1 c7 d# z5 P
Else3 l0 t6 k# K' ~+ W+ Q7 C% J) r1 D Q
'如果是空格,排除8 K3 F+ M( O1 b) C
If Asc(char) = 32 Then# {$ E P* A; A7 R* n( \7 r
getpychar = ""' [: w8 h7 E; p" M' U) {
Else+ U9 y6 j# q' K$ S
'9 `& m1 D- u- B1 F( y
getpychar = char* e, z9 b5 }! {' G3 z: [
End If- K+ {% i4 J( P5 _3 `: i
End If3 q/ H( G- u2 W' t
Else
3 l. |3 u: ]' y1 C2 w0 H tmp = 65536 + Asc(char)
3 z4 j1 }. t% } Select Case tmp, `* _" B8 J+ ]
Case 45217 To 45252: getpychar = "A"1 s2 K# c- K7 s! W1 X2 d* @
Case 45253 To 45760: getpychar = "B"# V8 g$ e. h$ }( b
Case 45761 To 46317: getpychar = "C"
' F' c. P" q+ J# @/ ]9 K5 b Case 46318 To 46825: getpychar = "D"
! O" s7 t; z- f- r Case 46826 To 47009: getpychar = "E"
& i9 E! k# \6 j9 |( E Case 47010 To 47296: getpychar = "F"+ o. E0 w4 q) c7 y6 w s
Case 47297 To 47613: getpychar = "G"
+ c" f# O- ~: H2 l Case 47614 To 48118: getpychar = "H"
* t2 w: T( X. ^4 k5 z* ` Case 48119 To 49061: getpychar = "J"9 J7 x8 h# p2 n3 R
Case 49062 To 49323: getpychar = "K"
# x; p; }6 \/ n$ s, S Case 49324 To 49895: getpychar = "L"# p% H3 p/ | b0 j
Case 49896 To 50370: getpychar = "M"
) T4 q3 i) L4 i4 P Case 50371 To 50613: getpychar = "N"& }+ z# Y2 L6 d" {
Case 50614 To 50621: getpychar = "O"4 Z5 }4 `0 i* c2 s* }3 r
Case 50622 To 50905: getpychar = "P"
1 @& l( i' C% t1 G5 z Case 50906 To 51386: getpychar = "Q"
" F5 ?3 F! I% U) Y8 m2 x# _ Case 51387 To 51445: getpychar = "R"
+ C' G: N+ A V; x9 L/ b Case 51446 To 52217: getpychar = "S"# s7 s# |1 o0 b- V! E/ q1 M# d1 n
Case 52218 To 52697: getpychar = "T"2 h( y) V5 e7 V
Case 52698 To 52979: getpychar = "W". w; V1 n# V# `$ J' y' f2 C3 E
Case 52980 To 53640: getpychar = "X"% A& W1 \6 f4 S* G
Case 53689 To 54480: getpychar = "Y"
% r& H0 y, }/ E+ q7 ] Case 54481 To 55289: getpychar = "Z", y1 O+ f$ z G+ e7 Z' _
Case Else: getpychar = "%"1 B. ?# p6 y \) \( r3 d* S; k
End Select2 n- E2 s3 X1 |: S( |0 u# y- {( b$ Z
End If
$ q! k( Y& E) W$ N8 aEnd Function
. m5 R I; e* k' QFunction getpy(str)% W% P+ l$ A3 [# E M
Dim i As Long1 R5 }# Z: M* N3 n/ R
For i = 1 To Len(str)4 N6 Z0 i6 p6 ^% K
getpy = getpy & getpychar(Mid(str, i, 1))
/ `$ S! q' x( n% a7 @ Next i
. x& p+ a* S: R" A5 {* d: nEnd Function
8 ]3 b; l1 D1 q" M
' W- ]4 N2 v+ ^* o1 u[ 本帖最后由 liangl923 于 2007-11-30 18:03 编辑 ] |
评分
-
查看全部评分
|