使用VBA函数在Excel单元格中生成拼音缩写

Function PinYin(Hz As String)   Dim PinMa As String   Dim MyPinMa As Variant   Dim Temp As Integer, i As Integer, j As Integer   PinMa = "a,20319,"   PinMa = PinMa & "b,20283,"   PinMa = PinMa & "c,19775,"   PinMa = PinMa & "d,19218,"   PinMa = PinMa & "e,18710,"   PinMa = PinMa & "f,18526,"   PinMa = PinMa & "g,18239,"   PinMa = PinMa & "h,17922,"   PinMa = PinMa & "j,17417,"   PinMa = PinMa & "k,16474,"   PinMa = PinMa & "l,16212,"   PinMa = PinMa & "m,15640,"   PinMa = PinMa & "n,15165,"   PinMa = PinMa & "o,14922,"   PinMa = PinMa & "p,14914,"   PinMa = PinMa & "q,14630,"   PinMa = PinMa & "r,14149,"   PinMa = PinMa & "s,14090,"   PinMa = PinMa & "t,13318,"   PinMa = PinMa & "w,12838,"   PinMa = PinMa & "x,12556,"   PinMa = PinMa & "y,11847,"   PinMa = PinMa & "z,11055,"   MyPinMa = Split(PinMa, ",")    For i = 1 To Len(Hz)   Temp = Asc(Mid(Hz, i, 1))       If Temp < 0 Then         Temp = Abs(Temp)         For j = 45 To 1 Step -2             If Temp <= Val(MyPinMa(j)) Then                 PinYin = PinYin & MyPinMa(j - 1)                 Exit For             End If         Next       Else          ' 保留非汉字字符       PinYin = PinYin & Mid(Hz, i, 1)       End If   Next   PinYin = Trim(PinYin) End Function

你可能感兴趣的:(Excel)