|
呵呵,treo的联系人查找一直是我的心病,我那么多联系人难道要一个一个改拼音么!!最近对outlook的宏研究的比较多,所以,研究了1天做出了自动把firstname(名字) 的汉字自动转化为拼音加入到 lastname(姓氏)字段中去。 自己用了下,感觉还是比较好用的!当然这么好的东西,要与吹友吧的同仁一起分享了 哈哈哈哈
, h4 {) b4 ~" h' |, i5 v. w% \) j! U3 j
" R: ?7 m( ~* }. N9 ?
) I1 V$ q: N4 T9 }有些生字无法转化出来,显示为“%”号,但是个人感觉不多,自己稍微改动下就好了。其实由于代码比较简单,所以只能照顾到常用字。有高手也可以把代码修改下,把拼音转化的部分增强。: i8 E4 {. H: A
4 \' G0 r1 [% I
使用环境: outlook2007[支持vba] 其他没有试过 我觉得03应该没问题
- e; S, R' m' @9 s! t P6 r2 k 修改vba运行权限: 工具》信任中心》宏安全性》不执行宏安全性检查 {用完后再改回系统默认}1 J: x$ k5 g" v6 {. T4 m$ @
" Y k! V, y; L M- f& k
使用方法: 先用treo和outlook同步
! ~6 f& @. m! {, t7 L9 x: s4 T7 } 工具》宏》vb编辑器 》新建模块 拷入代码F5运行就好了 3 _+ K* @" p Y9 s- b& @' @
+ Z) S: U- d- F2 Z
0 U2 e) j, }/ j: ?代码
/ b; \. j$ I/ e) Z0 }Option Explicit
0 Y8 [0 O* R7 x/ xSub setpinyin()
# K' }9 [, p( r+ Y+ w' ] Dim myolApp As New Outlook.Application6 {" L7 R( ^: c
Dim myNamespace As Outlook.NameSpace
- P ?$ ]6 h- m6 c7 i% q6 E Dim myAddresslists As Outlook.folder
! n$ \" S) [. ? Dim AddressList As Outlook.AddressList
n: z! ^& h$ l) I Dim item2 y- C8 W$ a, [) H! R0 a5 p
Dim temp1, temp2& w' c) ?4 p2 a5 ]
# E3 }% N* Y8 s Set myNamespace = myolApp.GetNamespace("MAPI")
3 e0 I9 q2 e5 H* I* C Set myAddresslists = myNamespace.GetDefaultFolder(olFolderContacts)
* K, o8 d# o; u; i+ v ' Set myolApp = myNamespace.GetDefaultFolder(olFolderInbox)
) {8 S( `3 g1 P2 @ For Each item In myAddresslists.Items4 c+ d0 ^9 ~; Q' A: v4 R( d
'temp1 = item.LastName & " " & item.FirstName% b) C; D6 X$ m* g! Z+ e% |9 s$ \
; w( _/ n# {7 T& X
If item.LastName = "" Then, P9 z' A% \# T
item.LastName = LCase(getpy(item.FirstName))
. i$ \2 m" N5 X* n item.Save
1 [6 C" R- O6 Y5 N# }! K Debug.Print item.LastName
/ ^% L/ @, r( w- x) u5 q; r- Z
v% ]" B$ r: {7 `5 M 'MsgBox item.LastName. P" T4 U" E: p0 u9 X* P
9 U7 `6 ?9 w, d2 C& j0 e1 z
End If, r$ {6 D8 m9 c* W; e
& @+ @4 H7 `; L) X+ h$ | Q2 ~
Next9 p9 a7 O/ T! Q6 I0 U* }
End Sub' f6 \( ~$ Z' H
6 z9 y( s* V% }
Function getpychar(char) As String
/ ^; B7 V% g: m On Error Resume Next! ~9 o7 h( x& q+ M. ^1 n
Dim tmp As String, vs1 As String8 e5 m+ f* i8 ]
. R, s% m, Z0 ^( l
If Asc(char) >= 0 And Asc(char) <= 127 Then
, i2 ?! m1 C6 ~ If char >= "a" And char <= "z" Then
. t1 B) w, c3 Y9 r, K% I( c3 l getpychar = Chr(Asc(char) - 32)
: w4 [4 u, y: k1 l1 A% W- F ElseIf char >= "A" And char <= "Z" Then
! Z% w+ ]% m5 V- {. N" { getpychar = char
! |) _; C, D' Y" N; U9 ~5 c Else
) S' M2 V* r9 @3 r9 | '如果是空格,排除9 h$ D1 M8 ?; p! z1 g/ r
If Asc(char) = 32 Then! o7 U7 D- G u$ Z8 e3 N1 U
getpychar = ""$ x! d8 c) O- _1 y$ [9 n
Else
3 U) ]7 l) o3 @! H# m5 Y4 I0 K5 W8 ? '2 U9 t# c! q& e# P4 T7 W2 W5 r
getpychar = char* P. A5 G2 W) [4 N& q4 c
End If
8 s% {' v8 m3 N& c; k! \ End If
$ ]' a1 O Y+ L) M. S/ T, N% E# M' h Else5 X& i! r' D5 G) F: T
tmp = 65536 + Asc(char)( U+ v( P5 U9 j0 ^$ B o S1 l
Select Case tmp( f) q8 P: Y, u% A/ L) _
Case 45217 To 45252: getpychar = "A"' Z9 C/ Q7 n4 q% J# \4 \
Case 45253 To 45760: getpychar = "B"9 Y O* m% z- s) H M( C
Case 45761 To 46317: getpychar = "C"! @8 l1 s6 i& g0 g- Y
Case 46318 To 46825: getpychar = "D": P. |! x [' z; v S6 ~
Case 46826 To 47009: getpychar = "E"
2 t: Q7 m# W3 X1 w Case 47010 To 47296: getpychar = "F". o2 _* W. Y) U5 |; @- F/ y
Case 47297 To 47613: getpychar = "G"+ h2 x" m% W8 K. s8 S4 y, m
Case 47614 To 48118: getpychar = "H"
/ H+ t4 c" E7 q6 B) C+ S" J6 Q Case 48119 To 49061: getpychar = "J"3 r# F0 t( ?* v2 Y
Case 49062 To 49323: getpychar = "K"
, G6 q5 u/ L# Z! W, n, p: h2 V Case 49324 To 49895: getpychar = "L"
5 X. d4 e5 w8 H) T! E! n7 | Case 49896 To 50370: getpychar = "M"+ S, Q* I% a5 e3 S! o; s6 u: J
Case 50371 To 50613: getpychar = "N"
( u- Q7 K- P/ t( u* I( O# R Case 50614 To 50621: getpychar = "O"2 t! x, ~% j6 h4 |6 k* A& [! d
Case 50622 To 50905: getpychar = "P") g+ k; U/ i, C+ e& e" Y3 P+ G
Case 50906 To 51386: getpychar = "Q"
* d. ?! p! X$ ?' u Case 51387 To 51445: getpychar = "R"5 L& n* x! w+ E* M1 A# x2 z
Case 51446 To 52217: getpychar = "S"
- R/ c- L' {. |( y Case 52218 To 52697: getpychar = "T"3 H' i, ]' a. q6 K# w
Case 52698 To 52979: getpychar = "W"' x% |1 B! ]! G. k
Case 52980 To 53640: getpychar = "X"- a, D J0 T/ p
Case 53689 To 54480: getpychar = "Y"
8 }+ s M* \) A3 t0 Q- e- C; Z9 ^ Case 54481 To 55289: getpychar = "Z"
4 w' a' _5 ?: B5 c% N* C Case Else: getpychar = "%"
3 g; i+ K7 q' N8 s4 W$ _ End Select( d$ ~+ n/ c4 e; u1 a- ~! {& V2 V& C
End If, ~! S- e' Z' [& G* I. R# N$ s4 N
End Function C7 R/ M+ Z! Z7 `& i
Function getpy(str) n2 N6 z/ f/ r* k/ q5 b9 I
Dim i As Long/ t( g1 B& W d
For i = 1 To Len(str)- i3 [8 t! T2 f: o8 R6 P$ @5 h) w8 n
getpy = getpy & getpychar(Mid(str, i, 1))
! ?4 E2 D) A5 c( d9 q; n Next i- {% d( N4 K9 x' E
End Function* d% l% `8 f! f$ c/ d/ j* R! [- z1 \
9 V3 t9 p& p0 ^1 p- `8 ^. v[ 本帖最后由 liangl923 于 2007-11-30 18:03 编辑 ] |
评分
-
查看全部评分
|