H を 16 進数に変換: debug.Print hex(asc("H")) >48 H を再度取得するために戻る: debug.Print chr(val("&H" & "48")) >H
簡単な例を挙げて詳細を送らせてください。あなたの答えは、16進数をASCIIに変換する方法であることを忘れないでください。そのためには、以下で説明する関数 hex_to_ascii を取得するだけです。
Sub test()
Dim str_word As Variant
str_word = "Hello Word"
Debug.Print "We've set=" & str_word
Dim hex_word As Variant
hex_word = str_to_hex(str_word)
Debug.Print "Just for convert to Hex format=" & hex_word
'48656C6C6F20576F7264
Dim ascii_word As Variant
ascii_word = hex_to_ascii(hex_word)
Debug.Print "Getting ASCII format from Hex=" & ascii_word
'072101108108111032087111114100
Dim hex_word_from_ascii As Variant
hex_word_from_ascii = ascii_to_hex(ascii_word)
Debug.Print "Finally converting Hex value to ascii=" & hex_word_from_ascii
'48656C6C6F20576F7264
Dim str_from_hex As Variant
str_from_hex = hex_to_str(hex_word_from_ascii)
Debug.Print "Remember=" & str_from_hex
'Hello Word
End Sub
Function str_to_hex(p_str As Variant) As Variant
Dim x As Long
Dim resp As Variant
Dim tmp As String
For x = 1 To Len(p_str)
tmp = Mid$(p_str, x, 1)
resp = resp & Hex(Asc(tmp))
Next
str_to_hex = resp
End Function
Function hex_to_str(p_hex As Variant) As Variant
Dim x As Long
Dim resp As Variant
Dim tmp As String
For x = 1 To Len(p_hex) Step 2
tmp = Mid$(p_hex, x, 2)
resp = resp & Chr(Val("&H" & tmp))
Next
hex_to_str = resp
End Function
Function hex_to_ascii(p_hex As Variant) As Variant
Dim x As Long
Dim resp As Variant
Dim tmp As String
For x = 1 To Len(p_hex) Step 2
tmp = Mid$(p_hex, x, 2)
resp = resp & Format(Val("&H" & tmp), "000")
Next
hex_to_ascii = resp
End Function
Function ascii_to_hex(p_ascii As Variant) As Variant
Dim x As Long
Dim resp As Variant
Dim tmp As String
For x = 1 To Len(p_ascii) Step 3
tmp = Mid$(p_ascii, x, 3)
resp = resp & Hex(tmp)
Next
ascii_to_hex = resp
End Function