人气 5879

[Excel技巧] EXCEL VBA自定义函数繁简体字转换 [复制链接]

开车载小猪 2017-7-27 16:58:39
我在做VBA服务的时候,常常会遇到香港或台湾的朋友,所以就有简体和繁体转换的需求,有些表格在大陆和港台2地来回转,书写的人一会简体一会繁体就造成了表格简繁不一,后期查找计算的时候会造成诸多不便。这里咱们利用系统API函数,用VBA写2个自定义函数,就可以轻松地解决简繁转换。
效果图如下:

1501146178140111.jpg

1501146178140111.jpg

详细源码:
Option Explicit ' 声明部分: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 LongPrivate Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As String) As Long ' 函数部分: ' 简转繁Public Function JtoF(ByVal Str As String) As String  Dim STlen As Long  Dim STf As String  STlen = lstrlen(Str)  STf = Space(STlen)  LCMapString &H804, &H4000000, Str, STlen, STf, STlen  JtoF = STfEnd Function ' 繁转简Public Function FtoJ(ByVal Str As String) As String  Dim STlen As Long  Dim STj As String  STlen = lstrlen(Str)  STj = Space(STlen)  LCMapString &H804, &H2000000, Str, STlen, STj, STlen  FtoJ = STjEnd Function
您需要登录后才可以回帖 登录 | 立即注册

QQ|手机版|精益人 ( 沪ICP备19004111号-1 )|网站地图

GMT+8, 2024-12-22 22:56 , Processed in 0.327977 second(s), 22 queries .

Powered by Lean.ren X3.5 Licensed  © 2001-2030 LEAN.REN