从字符到chr()

时间:2019-10-23 21:56:09

标签: excel vba

我有一个字符串,我想将每个字符转换为适当的ASCII字符。

Sub IterateCharactersObject()
    Dim ch As Characters, n As Long

    With ThisWorkbook.Sheets("Sheet1").Range("A1")
        For n = 1 To .Characters.Count
            Set ch = .Characters(n, 1)

            Debug.Print ch.Text & ", " & Asc(ch) '<-- what should go in place of Asc(ch)?

        Next n
    End With

End Sub

不确定我要查找的功能,似乎找不到。

如果我的字符串以“ A big ....”开头,则

  • n= 1输出为A, 65
  • n= 2输出为, 32

我本质上是在VBA中寻找Chr()函数的反函数

1 个答案:

答案 0 :(得分:1)

使用StringMid

Sub IterateCharactersObject()
    Dim ch As String, n As Long

    With ThisWorkbook.Sheets("Sheet1").Range("A1")
        For n = 1 To .Characters.Count
            ch = Mid(.Value, n, 1)

            Debug.Print ch & ", " & Asc(ch) '<-- what should go in place of Asc(ch)?

        Next n
    End With

End Sub

enter image description here