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