ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 8949|回复: 3

[分享] 汉字转拼音(全拼)_自定义函数

[复制链接]

TA的精华主题

TA的得分主题

发表于 2016-10-13 16:43 | 显示全部楼层 |阅读模式
Option Explicit

Function pinyin(p As String) As String
    Dim i As Integer
    i = Asc(p)
    Select Case i
        Case -20319 To -20318: pinyin = "a "
        Case -20317 To -20305: pinyin = "ai "
        Case -20304 To -20296: pinyin = "an "
        Case -20295 To -20293: pinyin = "ang "
        Case -20292 To -20284: pinyin = "ao "
        Case -20283 To -20266: pinyin = "ba "
        Case -20265 To -20258: pinyin = "bai "
        Case -20257 To -20243: pinyin = "ban "
        Case -20242 To -20231: pinyin = "bang "
        Case -20230 To -20052: pinyin = "bao "
        Case -20051 To -20037: pinyin = "bei "
        Case -20036 To -20033: pinyin = "ben "
        Case -20032 To -20027: pinyin = "beng "
        Case -20026 To -20003: pinyin = "bi "
        Case -20002 To -19991: pinyin = "bian "
        Case -19990 To -19987: pinyin = "biao "
        Case -19986 To -19983: pinyin = "bie "
        Case -19982 To -19977: pinyin = "bin "
        Case -19976 To -19806: pinyin = "bing "
        Case -19805 To -19785: pinyin = "bo "
        Case -19784 To -19776: pinyin = "bu "
        Case -19775 To -19775: pinyin = "ca "
        Case -19774 To -19764: pinyin = "cai "
        Case -19763 To -19757: pinyin = "can "
        Case -19756 To -19752: pinyin = "cang "
        Case -19751 To -19747: pinyin = "cao "
        Case -19746 To -19742: pinyin = "ce "
        Case -19741 To -19740: pinyin = "ceng "
        Case -19739 To -19729: pinyin = "cha "
        Case -19728 To -19726: pinyin = "chai "
        Case -19725 To -19716: pinyin = "chan "
        Case -19715 To -19541: pinyin = "chang "
        Case -19540 To -19532: pinyin = "chao "
        Case -19531 To -19526: pinyin = "che "
        Case -19525 To -19516: pinyin = "chen "
        Case -19515 To -19501: pinyin = "cheng "
        Case -19500 To -19485: pinyin = "chi "
        Case -19484 To -19480: pinyin = "chong "
        Case -19479 To -19468: pinyin = "chou "
        Case -19467 To -19290: pinyin = "chu "
        Case -19289 To -19289: pinyin = "chuai "
        Case -19288 To -19282: pinyin = "chuan "
        Case -19281 To -19276: pinyin = "chuang "
        Case -19275 To -19271: pinyin = "chui "
        Case -19270 To -19264: pinyin = "chun "
        Case -19263 To -19262: pinyin = "chuo "
        Case -19261 To -19250: pinyin = "ci "
        Case -19249 To -19244: pinyin = "cong "
        Case -19243 To -19243: pinyin = "cou "
        Case -19242 To -19239: pinyin = "cu "
        Case -19238 To -19236: pinyin = "cuan "
        Case -19235 To -19228: pinyin = "cui "
        Case -19227 To -19225: pinyin = "cun "
        Case -19224 To -19219: pinyin = "cuo "
        Case -19218 To -19213: pinyin = "da "
        Case -19212 To -19039: pinyin = "dai "
        Case -19038 To -19024: pinyin = "dan "
        Case -19023 To -19019: pinyin = "dang "
        Case -19018 To -19007: pinyin = "dao "
        Case -19006 To -19004: pinyin = "de "
        Case -19003 To -18997: pinyin = "deng "
        Case -18996 To -18978: pinyin = "di "
        Case -18977 To -18962: pinyin = "dian "
        Case -18961 To -18953: pinyin = "diao "
        Case -18952 To -18784: pinyin = "die "
        Case -18783 To -18775: pinyin = "ding "
        Case -18774 To -18774: pinyin = "diu "
        Case -18773 To -18527: pinyin = "dong "
        Case -18526 To -18519: pinyin = "fa "
        Case -18518 To -18502: pinyin = "fan "
        Case -18501 To -18491: pinyin = "fang "
        Case -18490 To -18479: pinyin = "fei "
        Case -18478 To -18464: pinyin = "fen "
        Case -18463 To -18449: pinyin = "feng "
        Case -18448 To -18448: pinyin = "fo "
        Case -18447 To -18447: pinyin = "fou "
        Case -18446 To -18240: pinyin = "fu "
        Case -18239 To -18238: pinyin = "ga "
        Case -18237 To -18232: pinyin = "gai "
        Case -18231 To -18221: pinyin = "gan "
        Case -18220 To -18212: pinyin = "gang "
        Case -18211 To -18202: pinyin = "gao "
        Case -18201 To -18185: pinyin = "ge "
        Case -18184 To -18184: pinyin = "gei "
        Case -18183 To -18182: pinyin = "gen "
        Case -18181 To -18013: pinyin = "geng "
        Case -18012 To -17998: pinyin = "gong "
        Case -17997 To -17989: pinyin = "gou "
        Case -17988 To -17971: pinyin = "gu "
        Case -17970 To -17965: pinyin = "gua "
        Case -17964 To -17962: pinyin = "guai "
        Case -17961 To -17951: pinyin = "guan "
        Case -17950 To -17948: pinyin = "guang "
        Case -17947 To -17932: pinyin = "gui "
        Case -17931 To -17929: pinyin = "gun "
        Case -17928 To -17923: pinyin = "guo "
        Case -17922 To -17760: pinyin = "ha "
        Case -17759 To -17753: pinyin = "hai "
        Case -17752 To -17734: pinyin = "han "
        Case -17733 To -17731: pinyin = "hang "
        Case -17730 To -17722: pinyin = "hao "
        Case -17721 To -17704: pinyin = "he "
        Case -17703 To -17702: pinyin = "hei "
        Case -17701 To -17698: pinyin = "hen "
        Case -17697 To -17693: pinyin = "heng "
        Case -17692 To -17684: pinyin = "hong "
        Case -17683 To -17677: pinyin = "hou "
        Case -17676 To -17497: pinyin = "hu "
        Case -17496 To -17488: pinyin = "hua "
        Case -17487 To -17483: pinyin = "huai "
        Case -17482 To -17469: pinyin = "huan "
        Case -17468 To -17455: pinyin = "huang "
        Case -17454 To -17434: pinyin = "hui "
        Case -17433 To -17428: pinyin = "hun "
        Case -17427 To -17418: pinyin = "huo "
        Case -17417 To -17203: pinyin = "ji "
        Case -17202 To -17186: pinyin = "jia "
        Case -17185 To -16984: pinyin = "jian "
        Case -16983 To -16971: pinyin = "jiang "
        Case -16970 To -16943: pinyin = "jiao "
        Case -16942 To -16916: pinyin = "jie "
        Case -16915 To -16734: pinyin = "jin "
        Case -16733 To -16709: pinyin = "jing "
        Case -16708 To -16707: pinyin = "jiong "
        Case -16706 To -16690: pinyin = "jiu "
        Case -16689 To -16665: pinyin = "ju "
        Case -16664 To -16658: pinyin = "juan "
        Case -16657 To -16648: pinyin = "jue "
        Case -16647 To -16475: pinyin = "jun "
        Case -16474 To -16471: pinyin = "ka "
        Case -16470 To -16466: pinyin = "kai "
        Case -16465 To -16460: pinyin = "kan "
        Case -16459 To -16453: pinyin = "kang "
        Case -16452 To -16449: pinyin = "kao "
        Case -16448 To -16434: pinyin = "ke "
        Case -16433 To -16430: pinyin = "ken "
        Case -16429 To -16428: pinyin = "keng "
        Case -16427 To -16424: pinyin = "kong "
        Case -16423 To -16420: pinyin = "kou "
        Case -16419 To -16413: pinyin = "ku "
        Case -16412 To -16408: pinyin = "kua "
        Case -16407 To -16404: pinyin = "kuai "
        Case -16403 To -16402: pinyin = "kuan "
        Case -16401 To -16394: pinyin = "kuang "
        Case -16393 To -16221: pinyin = "kui "
        Case -16220 To -16217: pinyin = "kun "
        Case -16216 To -16213: pinyin = "kuo "
        Case -16212 To -16206: pinyin = "la "
        Case -16205 To -16203: pinyin = "lai "
        Case -16202 To -16188: pinyin = "lan "
        Case -16187 To -16181: pinyin = "lang "
        Case -16180 To -16172: pinyin = "lao "
        Case -16171 To -16170: pinyin = "le "
        Case -16169 To -16159: pinyin = "lei "
        Case -16158 To -16156: pinyin = "leng "
        Case -16155 To -15960: pinyin = "li "
        Case -15959 To -15959: pinyin = "lia "
        Case -15958 To -15945: pinyin = "lian "
        Case -15944 To -15934: pinyin = "liang "
        Case -15933 To -15921: pinyin = "liao "
        Case -15920 To -15916: pinyin = "lie "
        Case -15915 To -15904: pinyin = "lin "
        Case -15903 To -15890: pinyin = "ling "
        Case -15889 To -15879: pinyin = "liu "
        Case -15878 To -15708: pinyin = "long "
        Case -15707 To -15702: pinyin = "lou "
        Case -15701 To -15682: pinyin = "lu "
        Case -15681 To -15668: pinyin = "lv "
        Case -15667 To -15662: pinyin = "luan "
        Case -15661 To -15660: pinyin = "lue "
        Case -15659 To -15653: pinyin = "lun "
        Case -15652 To -15641: pinyin = "luo "
    End Select
End Function
Function getpy(str)
    Dim i As Integer
    For i = 1 To Len(str)
      getpy = getpy & pinyin(Mid(str, i, 1))
    Next i
End Function
'未转换成功的字可以看下acs码,在case里增加。
Sub test()
    MsgBox Asc("昊")
End Sub



补充内容 (2016-10-19 16:18):
有人提醒我部分代码来自网上,应写明出自,我都不知道什么时候copy的了,说明一下吧。
本贴有部分代码copy网上,此资料只是为了方便记录使用,请使用者不要用于收费。

补充内容 (2016-10-19 16:20):
收费与我无关,请从其他网页copy。

TA的精华主题

TA的得分主题

 楼主| 发表于 2016-10-13 16:52 | 显示全部楼层
C:\Users\xuyj\Desktop\无标题.png
无标题.png

TA的精华主题

TA的得分主题

发表于 2016-10-13 16:56 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2018-8-17 10:36 | 显示全部楼层
发现错误一个,断、短都被翻译成了“dong”而不是"duan"
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2025-1-12 07:38 , Processed in 0.021374 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表