Excel:单词完成后重复VBA脚本

时间:2019-01-30 15:27:32

标签: excel vba

我仍在学习如何在VBA中制作脚本。 现在,我想创建将文本从单元格转换为Unicode Little Endian Hex的脚本。我有只适用于第一个字符的脚本。我应该如何应用循环切换到下一个字母,将其添加到打印并在文本结束后完成脚本?

Function Text2LE(Character As String)    
Dim x As Long
x = AscW(Character)
If x < 16 Then
  Text2LE = "000" & Hex(AscW(Character))
  Text2LE = Right(Text2LE, 2) & Left(Text2LE, 2)
ElseIf x < 256 Then
  Text2LE = "00" & Hex(AscW(Character))
  Text2LE = Right(Text2LE, 2) & Left(Text2LE, 2)
Else
  Text2LE = "0" & Hex(AscW(Character))
  Text2LE = Right(Text2LE, 2) & Left(Text2LE, 2)
End If
End Function

1 个答案:

答案 0 :(得分:0)

您需要像遍历字符串中的Character并使用函数将其转换的操作!然后将十六进制分组在一起并显示或使用! (不确定在调试窗口中是否显示十六进制)

sub Convert()
 Dim i as long
 Dim string_to_convert as string
 Dim Hex as String

 For i = 1 to len(string_to_convert)
   Hex = Hex + Text2LE(Mid(string_to_convert, i, 1))
 Next i

 debug.Print Hex

end sub