For cells with 'gibberish' on an Excel file, I need to present them (e.g. in another cell or at least, for now, in a message box), in the language they originate from.
I found a hint for a solution at https://www.di-mgt.com.au/howto-convert-vba-unicode-to-utf8.html, but couldn't pull through a working code.
What I did:
- merge the 'variables' block into one (there are two there),
- paste all the functions in below the declared variables (as one converts undecoded Unicode strings to bytes, and the other to properly encoded Unicode strings),
- and assuming I want to display cell A1, I slightly modified the last part of the code that should do the trick, to:
Public Sub Test_Utf8String()
Dim abData() As Byte
Dim b() As Byte
Dim a As String
Dim s As String
Dim i As Integer
With ActiveSheet
abData = StrConv(.Cells(1, 1).Value, vbFromUnicode)
a = ""
For i = 0 To UBound(abData)
If i = UBound(abData) Then
a = a & Hex(abData(i))
Else:
a = a & Hex(abData(i)) & ""
End If
Next
b = Utf8BytesFromString(a)
s = Utf8BytesToString(b)
MsgBox (s)
End With
End Sub
It throws errors I cannot cope with.