<span style="color: rgb(51, 51, 51); font-family: 'Microsoft Yahei', 微软雅黑, arial, 宋体, sans-serif; font-size: 16px; line-height: 28px; text-align: justify;">方法:EXCEL->菜单"工具"->“宏”->“Visual Basic编辑器";</span>
<span style="color: rgb(51, 51, 51); font-family: 'Microsoft Yahei', 微软雅黑, arial, 宋体, sans-serif; font-size: 16px; line-height: 28px; text-align: justify;"><span style="color: rgb(51, 51, 51); font-family: 'Microsoft Yahei', 微软雅黑, arial, 宋体, sans-serif; font-size: 16px; line-height: 28px; text-align: justify;">"Visual Basic编辑器-Book1”窗口->“插入”->“模块</span>
</span>
Function GetUnicode(str As String) As String
'输出str的unicode码
Dim chrTmp As String
Dim ByteLower As String
Dim ByteUpper As String
Dim strReturn As String
For i = 1 To Len(str)
chrTmp$ = Mid(str, i, 1)
ByteLower$ = Hex$(AscB(MidB$(chrTmp$, 1, 1)))
If Len(ByteLower$) = 1 Then '如果低字节长度为1,补一个0
ByteLower$ = "0" & ByteLower$
End If
ByteUpper$ = Hex$(AscB(MidB$(chrTmp$, 2, 1)))
If Len(ByteUpper$) = 1 Then '如果高字节长度为1,补一个0
ByteUpper$ = "0" & ByteUpper$
End If
strReturn$ = "0x" & ByteUpper$ & ByteLower$
Next
GetUnicode = strReturn
End Function
Function GetUnicodeDec(str As String) As String
'输出str的unicode码值
Dim chrTmp As String
Dim ByteLower As String
Dim ByteUpper As String
chrTmp$ = Mid(str, i, 1)
ByteLower$ = AscB(MidB$(chrTmp$, 1, 1))
ByteUpper$ = AscB(MidB$(chrTmp$, 2, 1))
GetUnicodeDec = ByteUpper*256 + ByteLower
End Function
Function GetGBK(strInput As String) As String
'输出str的gbk码
Dim x() As Byte
Dim i As Integer
x = strInput
x = StrConv(x, vbFromUnicode)
If (UBound(x) - LBound(x) + 1) / Len(strInput) <> 2 Then
GetGBK = "你输入包含非中文字符"
Else
For i = 0 To UBound(x) Step 2
GetGBK = GetGBK & Hex(x(i<span style="font-family: Arial, Helvetica, sans-serif;">+ 1</span><span style="font-family: Arial, Helvetica, sans-serif;">)) & Hex(x(i))</span>
Next i
GetGBK = Trim(GetGBK)
End If
End Function