使用方法:
1、 開啟要生成的EXCEL檔案,選擇工具--宏---Visual Basic編輯器(快捷鍵:alt+f11)。
2、 選擇:插入--模組--把下方的程式碼貼上到裡面,儲存。
3、 程式碼部分:
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)
PinYin = Trim(PinYin)
End Function
4、 儲存後,回到EXCEL內容編輯介面 。
5、 在需要生成助記碼的地方。輸入公式 =pinyin(相應的漢字單元格)。
使用方法:
1、 開啟要生成的EXCEL檔案,選擇工具--宏---Visual Basic編輯器(快捷鍵:alt+f11)。
2、 選擇:插入--模組--把下方的程式碼貼上到裡面,儲存。
3、 程式碼部分:
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
4、 儲存後,回到EXCEL內容編輯介面 。
5、 在需要生成助記碼的地方。輸入公式 =pinyin(相應的漢字單元格)。