作者:绿色风
分类:
时间:2022-08-17
浏览:164
楼主 罗刚君 |
Q:如何用VBA实现批量简繁转换? A:在简体中文的操作系统中可以使用如下代码进行转换,繁体系统中则不适用。
- Dim STlen As Long, STf As String, str As String, STj As String
- Private Declare Function LCMapString Lib "kernel32" Alias "LCMapStringA" (ByVal Locale As Long, ByVal dwMapFlags As Long, ByVal lpSrcStr As String, ByVal cchSrc As Long, ByVal lpDestStr As String, ByVal cchDest As Long) As Long
- Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As String) As Long
- Sub 简转繁()
- On Error GoTo err
- Dim cell As Range
- For Each cell In Intersect(Selection, ActiveSheet.UsedRange)
- str = cell
- STlen = lstrlen(str)
- STf = Space(STlen)
- LCMapString &H804, &H4000000, str, STlen, STf, STlen
- cell.Value = STf
- Next
- err:
- End Sub
- Sub 繁转简()
- On Error GoTo err
- Dim cell As Range
- For Each cell In Intersect(Selection, ActiveSheet.UsedRange)
- str = cell
- STlen = lstrlen(str)
- STj = Space(STlen)
- LCMapString &H804, &H2000000, str, STlen, STj, STlen
- cell.Value = STj
- Next
- err:
- End Sub
|
2楼 成就滋味 |
学习了,感谢分享哦 |
免责声明
有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素,
经与ExcelTip.Net站长Apolloh商议并征得其同意,
现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示,
供有需要的人士查询使用,也慰缅曾经的论坛时代。
所示各个帖子的原作者如对版权有异议,
可与本人沟通提出,或于本站点留言,我们会尽快处理。
在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一