- 三:点击编辑,输入如下代码片段,点击保存,并选择是
Function pinyin(p As String) As String
i = Asc(p)
Select Case i
Case - To -: pinyin = "A"
Case - To -: pinyin = "B"
Case - To -: pinyin = "C"
Case - To -: pinyin = "D"
Case - To -: pinyin = "E"
Case - To -: pinyin = "F"
Case - To -: pinyin = "G"
Case - To -: pinyin = "H"
Case - To -: pinyin = "J"
Case - To -: pinyin = "K"
Case - To -: pinyin = "L"
Case - To -: pinyin = "M"
Case - To -: pinyin = "N"
Case - To -: pinyin = "O"
Case - To -: pinyin = "P"
Case - To -: pinyin = "Q"
Case - To -: pinyin = "R"
Case - To -: pinyin = "S"
Case - To -: pinyin = "T"
Case - To -: pinyin = "W"
Case - To -: pinyin = "X"
Case - To -: pinyin = "Y"
Case - To -: pinyin = "Z"
Case Else: pinyin = p
End Select
End Function
Function getpy(str)
For i = To Len(str)
getpy = getpy & pinyin(Mid(str, i, ))
Next i
End Function
-
四:回到excel,鼠标定位到“拼音码”列第一行(C2单元格)。在函数框中输入=getpy(B2),(调用自定义函数,获取B2单元格中汉字内容首字母)回车,可以看到获取到B2单元格中内容的首字母
- 五:鼠标定位到单元格C2右下角,光标变成黑色十字,按住鼠标左键一直往下拉。获取全部内容的拼音码。