excel技巧——导出汉字姓名首字母
1 导入一张含有姓名的表格,把姓名放到a列中,在b列中将要导出拼音。2 现在我们按住alt+f11,打开vb编辑窗口,单击插入——模块,弹出代码编辑框。3 在代码编辑框中输入:option explicitfunction py(tt as string) as variantdim i%, temp$ py = "" for i = 1 to len(tt) temp = asc(mid$(tt, i, 1)) if temp > 255 or temp < 0 then py = py & pinyin(mid$(tt, i, 1)) else py = py & lcase(mid$(tt, i, 1)) end if next iend functionfunction pinyin(mystr as string) as variant on error resume next mystr = strconv(mystr, vbnarrow) if asc(mystr) > 0 or err.number = 1004 then pinyin = "" pinyin = application.worksheetfunction.vlookup(mystr, [{"吖","a";"八","b";"嚓","c";"搭","d";"蛾","e";"发","f";"噶","g";"铪","h";"击","j";"咔","k";"垃","l";"妈","m";"拿","n";"噢","o";"啪","p";"七","q";"然","r";"仨","s";"他","t";"挖","w";"夕","x";"压","y";"座","z"}], 2)end function 关闭vb窗口。4 现在转到工作表中,我们在b2中输入=py(a2),回车我们就看到姓名的拼音首字母显示出来了。5 我们用填充手柄把b列中的单元格全部填满,这时候我们要的效果就出现了。end 20210311