Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88835

How to display badly decoded Unicode characters in Excel cells in their original language?

$
0
0

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:

  1. merge the 'variables' block into one (there are two there),
  2. 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),
  3. 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.


Viewing all articles
Browse latest Browse all 88835


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>