excel表格获取汉字大写首拼函数(自定义宏)

时间:2023-03-09 15:06:20
excel表格获取汉字大写首拼函数(自定义宏)

打开excel,按Alt+F11,插入-模块,复制粘贴下边的函数

 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表格里边就可以使用这个函数了,例如:

=getpy(A1)

搞掂,不过如果需要永久这些大写首拼的话需要保存支持宏的格式,否则下次再打开就丢失啦,也可以复制出来,自己衡量吧~