|
呵呵,treo的联系人查找一直是我的心病,我那么多联系人难道要一个一个改拼音么!!最近对outlook的宏研究的比较多,所以,研究了1天做出了自动把firstname(名字) 的汉字自动转化为拼音加入到 lastname(姓氏)字段中去。 自己用了下,感觉还是比较好用的!当然这么好的东西,要与吹友吧的同仁一起分享了 哈哈哈哈- C1 L! p- U. x, p/ B$ L1 H
' }! Q$ }1 a% s% v1 ?: \+ V) ]- Z4 | a% R. t
& D7 M! W- x0 w( D
有些生字无法转化出来,显示为“%”号,但是个人感觉不多,自己稍微改动下就好了。其实由于代码比较简单,所以只能照顾到常用字。有高手也可以把代码修改下,把拼音转化的部分增强。- a" }1 O* Z. @3 C! M2 j
! X$ e) z2 h& V! A& ?: g, T使用环境: outlook2007[支持vba] 其他没有试过 我觉得03应该没问题
* C6 `. w7 v* K# i/ s0 Z0 g& O 修改vba运行权限: 工具》信任中心》宏安全性》不执行宏安全性检查 {用完后再改回系统默认}6 F* L" O" R& `2 t
4 i# j: g3 I9 V3 W! S; P; T使用方法: 先用treo和outlook同步" M! y5 i7 ?! a v; u
工具》宏》vb编辑器 》新建模块 拷入代码F5运行就好了
2 |) x5 U& ], N& r1 I2 ~3 y3 ]- d7 u+ I; p
4 Y7 W4 q( c) f) }9 f
代码
/ ~/ |3 w- A5 d9 I5 h7 G' f( AOption Explicit" a1 [& m" ^& P& }7 `9 `2 v" O
Sub setpinyin(), G, ?' c# S/ j( a) b8 G7 ~, x
Dim myolApp As New Outlook.Application
9 ^2 b2 |+ K$ H2 _( {* Y Dim myNamespace As Outlook.NameSpace
; N3 f' k9 i9 G" Q& R7 b; v* _ Dim myAddresslists As Outlook.folder
9 L3 F7 y! }3 j Dim AddressList As Outlook.AddressList3 y* M+ X# G- ]% o7 Z. c) u/ h( R5 {
Dim item
" m+ p, t; c2 R8 `9 a Dim temp1, temp2
( v( Q, N0 j. e! }2 t
& d3 l4 v8 b0 c; `( d& S2 R8 @# } Set myNamespace = myolApp.GetNamespace("MAPI")" {' L7 I$ V% E
Set myAddresslists = myNamespace.GetDefaultFolder(olFolderContacts)
3 n, D$ T) t6 Z1 Y ' Set myolApp = myNamespace.GetDefaultFolder(olFolderInbox)5 A' u$ i2 Q; D9 t
For Each item In myAddresslists.Items" Z, v0 A0 b7 u: Q, c+ Q
'temp1 = item.LastName & " " & item.FirstName) f* |$ }! u3 [/ H: g7 g
# P2 h( Z( Y: b If item.LastName = "" Then
9 l2 r5 ?9 W4 \% Z item.LastName = LCase(getpy(item.FirstName))
, W5 i7 w) _/ o& | item.Save
; {4 U" [; r* S Debug.Print item.LastName
8 Y) ?- _- H! r* t7 h- O$ F
- ]7 e' b& _8 P 'MsgBox item.LastName
- d, N6 G0 w/ A ^ ' a# N' l+ c" p# J# J! o
End If
5 q8 v/ y ?1 [, F5 F! n
2 t4 h) u0 X) p) L- s% ~( a Next4 i8 j, T2 ^8 n' z$ c. N
End Sub% g% V1 D0 \( K( |8 s
+ X4 | @- ^+ N* `& Y
Function getpychar(char) As String
/ M1 D2 r6 k" j2 B% p/ Q On Error Resume Next% b* ^; I+ r" u6 W7 i4 I6 l$ z
Dim tmp As String, vs1 As String
( V: T& t% d5 J5 b7 `8 Z7 V
j/ \# U- l/ S5 w If Asc(char) >= 0 And Asc(char) <= 127 Then* N D* W+ S. S6 `% U e6 l
If char >= "a" And char <= "z" Then" ^. D) z- }$ |- Y3 F9 O) j
getpychar = Chr(Asc(char) - 32)$ k' e1 _: m! R: y3 W
ElseIf char >= "A" And char <= "Z" Then
! ^) U) F9 O1 p }1 Z# O getpychar = char
# N2 w1 D* ]% s" P, u Else' N. K. d( C3 r! D0 ?0 S! i6 g
'如果是空格,排除
{6 r. @" _. G* a& K: k& Q1 O# C If Asc(char) = 32 Then
9 [! F' S, J; w% L: P$ n c) U" P getpychar = ""
; S+ J) K3 Y1 l3 g& y Else
( ?% b( b$ h, g) z" G- p$ z '
/ u) H- F; W$ v2 ^' P0 Q- { getpychar = char: e; n- f6 l& A7 Y% q# I+ S$ q& I
End If/ F+ U q4 j; n+ Y: F# {) [& F
End If
4 o- e# l. B3 O( L$ ]6 J Else
& c' r% k7 S4 } tmp = 65536 + Asc(char)
3 U, Z0 s5 |* X+ F1 [/ m Select Case tmp% v# Y0 m' q$ w E6 E D
Case 45217 To 45252: getpychar = "A"' n$ d0 N) q) r9 y' {
Case 45253 To 45760: getpychar = "B"
. L1 q6 p) y( ]5 A" x Case 45761 To 46317: getpychar = "C"5 x1 X/ h/ m+ g& v* M- o" ]4 N
Case 46318 To 46825: getpychar = "D"
# a+ O: s* A, _ Case 46826 To 47009: getpychar = "E"
9 T/ G/ \5 t5 ~ Case 47010 To 47296: getpychar = "F"
2 c f' {$ |5 L& ]2 s* e) z Case 47297 To 47613: getpychar = "G". o8 `6 h- \& k7 @$ G, c V1 W0 b
Case 47614 To 48118: getpychar = "H"6 H" Y( Z B/ r, w1 _# k2 P, W& l
Case 48119 To 49061: getpychar = "J"8 v7 @' \6 r% V( |- Q7 D# f. T# R
Case 49062 To 49323: getpychar = "K"' Y# n* B* D2 n* W* C2 `. t
Case 49324 To 49895: getpychar = "L"5 I) l5 Q9 ]+ m& l4 S+ Q9 f
Case 49896 To 50370: getpychar = "M"
4 `, |! u: Z/ i- J4 E+ L7 n Case 50371 To 50613: getpychar = "N"7 k1 B9 \' e9 \8 ~' q+ p
Case 50614 To 50621: getpychar = "O"
7 ?5 S- X: c z% { Case 50622 To 50905: getpychar = "P"" g" F+ v: s2 t9 a# b: Q: a
Case 50906 To 51386: getpychar = "Q"! e0 \2 \( @$ P5 {, p2 V" {
Case 51387 To 51445: getpychar = "R"* H% {( r. Y/ |% n* E9 l1 N# |+ V
Case 51446 To 52217: getpychar = "S"
) `8 N ~- U. r J$ t/ e0 R n( ? Case 52218 To 52697: getpychar = "T"# n# j0 L+ V7 k/ [7 x& I
Case 52698 To 52979: getpychar = "W"* J% r0 j# x$ q# t1 o- z/ E( P
Case 52980 To 53640: getpychar = "X"7 M7 Q% y A0 a I8 `% S% m
Case 53689 To 54480: getpychar = "Y"
# q: i$ R/ _0 c0 T- h Case 54481 To 55289: getpychar = "Z"7 b) F! v& T# D! M) C" k; f
Case Else: getpychar = "%"
$ l6 @. ~- V$ ~! M3 J End Select& y- U3 H, B) |6 B/ t
End If
8 b; I, Q' `; Z5 F2 B8 XEnd Function9 Y& \- D* F1 d7 P
Function getpy(str)0 t5 Y9 e; \: f% A5 l N- }( p
Dim i As Long
# A8 e1 J) A: T3 \( }# N5 S/ @ For i = 1 To Len(str)
, t: k/ `: s ]+ L getpy = getpy & getpychar(Mid(str, i, 1))# C' h9 G; c q$ ]* o6 U
Next i% W1 P, e+ P! V5 E
End Function
2 n& C5 M1 Q% z; j" M" S
$ a0 Y' _ ~" q( \/ V[ 本帖最后由 liangl923 于 2007-11-30 18:03 编辑 ] |
评分
-
查看全部评分
|