Option Explicit
function PY (TT as String) as Variant ' Custom function, purpose: To change a group of Chinese characters into the first letter of a set of Chinese pinyin.
Dim i%, temp$
PY = ""
For i = 1 to Len (TT)
temp = ASC (mid$ (TT, I, 1))
If temp > 255 Or Temp < 0 Then ' is Kanji?
py = py & Pinyin (mid$ (TT, I, 1)) ' converted to pinyin initials,
Else
py = py & LCase (mid$ (TT, I, 1)) ' Convert English alphabet
End If
Next I
End Function
function Pinyin (mystr as String) as Variant ' custom functions, purpose: To change a single Chinese character to the first letter of Pinyin.
On Error Resume Next
MyStr = StrConv (mystr, Vbnarrow)
If ASC (mystr) > 0 Or err.number = 1004 then pinyin = ""
Pinyin = Application.WorksheetFunction.VLookup (MyStr, [{"Acridine", "A"; " Eight "," B ";" Cha "," C ";" Otah "," D ";" 鵽 "," E ";" "," F ";" 猤 "," G ";" Hafnium "," H ";" Inceѕt "," J ";" Ka "," K ";" "," L ";" 嘸 "," M ";" Temperature "," N ";" Oh "," O ";" 妑 "," P ";" Seven "," Q ";" 囕 "," R ";" Three "," S ";" He "," T "; 屲 "," W ";" Xi "," X ";" Ya "," Y ";" As "," Z "}], 2)
End Function
To do this, open the Excel document, press ALT+F11, open the VBE editor, insert the--module, copy the code above, and close the VBE. Return to the worksheet, enter a formula, such as: =py (A2), you can extract the first letter of the A2 cell pinyin.
Originating From: http://www.ittribalwo.com/article/1542.html
Excel extract cell Chinese pinyin first letter