This is a short update on my post of Sep 28, 2020 on reading Unicode text in VBA.
That post mentioned the limitations of old VB statements which cannot handle Unicode:
Open FullName For Input As #handle : Line Input #1, strLine
I am reposting the module as ADOStream.bas with the following functions:
MessageBox(Prompt As String, Optional Buttons As Long = VbMsgBoxStyle.vbOKOnly, Optional Title As String = "Message") As VbMsgBoxResult
MessageBoxW from the Windows API correctly displays international Unicode characters.
ReadFileBOMCharset(ByVal filename As String, ByRef charset As String) As Long
Infer the encoding of a file.
CharsetFromBytes(bytes() As Byte) As String
Infer charset if there is any Byte Order Marker in the first 3 bytes of content.
ReadADOStreamFile(ByVal FullName As String, ByRef text As String, ByRef charset As String, Optional ByRef numchars As Long = -1) As Long
Read the contents of a file as text, inferring the encoding.
WriteADOStreamText(ByVal filename As String, ByRef text As String, Optional ByRef charset As String) As Long
Write text to a file.
Function ReadADOStreamBytes(ByVal filename As String, ByRef bytes() As Byte, Optional ByRef numchars As Long = -1) As Long
Read the contents of a file as a byte array, including any Byte Order Marker (BOM).