vba 全拼_通用中文转拼音函数(全拼完整版)适合Excel与Access VBA,支持是否加空格及首字母是否大写...

该博客分享了一个适用于Excel和Access VBA的全拼转换函数,能够根据需求设置拼音之间的空格和首字母大小写。函数通过枚举汉字Unicode范围来实现中文到拼音的转换,提供了多种输出格式供用户选择。
摘要由CSDN通过智能技术生成

通用中文转拼音函数(全拼完整版)同时适合Excel与Access VBA,支持多种设置选项,如是否加空格及首字母是否大写

1.生成效果1: wang yu hong

2.生成效果2: wangyuhong

3.生成效果3:WangYuHong

可以根据自己的需要进行不同的设置,以获取适合自己的中文转拼音格式

'通用中文转拼音函数(全拼完整版)同时适合Excel与Access VBA,支持多种设置选项,如是否加空格及首字母是否大写

'blnNeedSpace 2个拼音之间是否要加空格

'blnFirstUpper 拼音首字是否大写

' tmtony - Office交流网

Public Function gf_GetPy(str As String, Optional blnNeedSpace As Boolean = True, Optional blnFirstUpper As Boolean = False)

Dim i As Long

Dim j As Long

Dim strTmp As String

For i = 1 To Len(str)

strTmp = SimplePinYin(Mid(str, i, 1))

If blnNeedSpace = False Then strTmp = Trim(strTmp)

If blnFirstUpper Then

If Len(strTmp) > 0 Then

strTmp = UCase(Left(strTmp, 1)) & Mid(strTmp, 2)

End If

End If

gf_GetPy = gf_GetPy & strTmp

Next i

End Function

'获取单个中文汉字的全拼间函数

Private Function SimplePinYin(p As String) As String

Dim i As Long

i = Asc(p)

Select Case i

Case -20319 To -20318: SimplePinYin = "a "

Case -20317 To -20305: SimplePinYin = "ai "

Case -20304 To -20296: SimplePinYin = "an "

Case -20295 To -20293: SimplePinYin = "ang "

Case -20292 To -20284: SimplePinYin = "ao "

Case -20283 To -20266: SimplePinYin = "ba "

Case -20265 To -20258: SimplePinYin = "bai "

Case -20257 To -20243: SimplePinYin = "ban "

Case -20242 To -20231: SimplePinYin = "bang "

Case -20230 To -20052: SimplePinYin = "bao "

Case -20051 To -20037: SimplePinYin = "bei "

Case -20036 To -20033: SimplePinYin = "ben "

Case -20032 To -20027: SimplePinYin = "beng "

Case -20026 To -20003: SimplePinYin = "bi "

Case -20002 To -19991: SimplePinYin = "bian "

Case -19990 To -19987: SimplePinYin = "biao "

Case -19986 To -19983: SimplePinYin = "bie "

Case -19982 To -19977: SimplePinYin = "bin "

Case -19976 To -19806: SimplePinYin = "bing "

Case -19805 To -19785: SimplePinYin = "bo "

Case -19784 To -19776: SimplePinYin = "bu "

Case -19775 To -19775: SimplePinYin = "ca "

Case -19774 To -19764: SimplePinYin = "cai "

Case -19763 To -19757: SimplePinYin = "can "

Case -19756 To -19752: SimplePinYin = "cang "

Case -19751 To -19747: SimplePinYin = "cao "

Case -19746 To -19742: SimplePinYin = "ce "

Case -19741 To -19740: SimplePinYin = "ceng "

Case -19739 To -19729: SimplePinYin = "cha "

Case -19728 To -19726: SimplePinYin = "chai "

Case -19725 To -19716: SimplePinYin = "chan "

Case -19715 To -19541: SimplePinYin = "chang "

Case -19540 To -19532: SimplePinYin = "chao "

Case -19531 To -19526: SimplePinYin = "che "

Case -19525 To -19516: SimplePinYin = "chen "

Case -19515 To -19501: SimplePinYin = "cheng "

Case -19500 To -19485: SimplePinYin = "chi "

Case -19484 To -19480: SimplePinYin = "chong "

Case -19479 To -19468: SimplePinYin = "chou "

Case -19467 To -19290: SimplePinYin = "chu "

Case -19289 To -19289: SimplePinYin = "chuai "

Case -19288 To -19282: SimplePinYin = "chuan "

Case -19281 To -19276: SimplePinYin = "chuang "

Case -19275 To -19271: SimplePinYin = "chui "

Case -19270 To -19264: SimplePinYin = "chun "

Case -19263 To -19262: SimplePinYin = "chuo "

Case -19261 To -19250: SimplePinYin = "ci "

Case -19249 To -19244: SimplePinYin = "cong "

Case -19243 To -19243: SimplePinYin = "cou "

Case -19242 To -19239: SimplePinYin = "cu "

Case -19238 To -19236: SimplePinYin = "cuan "

Case -19235 To -19228: SimplePinYin = "cui "

Case -19227 To -19225: SimplePinYin = "cun "

Case -19224 To -19219: SimplePinYin = "cuo "

Case -19218 To -19213: SimplePinYin = "da "

Case -19212 To -19039: SimplePinYin = "dai "

Case -19038 To -19024: SimplePinYin = "dan "

Case -19023 To -19019: SimplePinYin = "dang "

Case -19018 To -19007: SimplePinYin = "dao "

Case -19006 To -19004: SimplePinYin = "de "

Case -19003 To -18997: SimplePinYin = "deng "

Case -18996 To -18978: SimplePinYin = "di "

Case -18977 To -18962: SimplePinYin = "dian "

Case -18961 To -18953: SimplePinYin = "diao "

Case -18952 To -18784: SimplePinYin = "die "

Case -18783 To -18775: SimplePinYin = "ding "

Case -18774 To -18774: SimplePinYin = "diu "

Case -18773 To -18527: SimplePinYin = "dong "

Case -18526 To -18519: SimplePinYin = "fa "

Case -18518 To -18502: SimplePinYin = "fan "

Case -18501 To -18491: SimplePinYin = &#

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值