zjshidr

导航

EXCEL生成助记码宏

1、 打开要生成的EXCEL文件,选择工具--宏---Visual Basic编辑器(快捷键:alt+f11)
2、 选择:插入--模块--把下方的代码粘贴到里面,保存。
3、代码
4、 保存后,回到EXCEL内容编辑界面 。
5、 在需要生成助记码的地方。输入公式 =pinyin(相应的汉字单元格)。
注意:1、启用宏2、列格式为常规
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

posted on 2024-12-16 11:14  涵若曦  阅读(1)  评论(0编辑  收藏  举报