Excel 怎样用VBA提取中文字符
2个回答
展开全部
'GB2312范围: 0xA1A1 - 0xFEFE
'GBK范围: 0x8140 - 0xFEFE
Public Function HIBYTE(ByVal Word As Integer) As Byte
HIBYTE = (Word And &HFF00&) \ &H100
End Function
Public Function LOBYTE(ByVal Word As Integer) As Byte
LOBYTE = Word And &HFF
End Function
'按GB2312提取中文字符
Function TiQu(str As String)
Dim i As Integer
Dim nAsc As Integer
Dim bytHigh As Byte
Dim bytLow As Byte
Dim strChar As String
Dim strTemp As String
For i = 1 To Len(str)
strChar = Mid(str, i, 1)
nAsc = Asc(strChar)
bytLow = LOBYTE(nAsc)
bytHigh = HIBYTE(nAsc)
If bytLow >= &HA1 And bytHigh >= &HA1 Then
strTemp = strTemp & strChar
End If
Next
TiQu = strTemp
End Function
'例
Sub Example1()
MsgBox TiQu("d中f国l;a世sjd界f;a")
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询