Search notes:

VBA open statement: character encoding

Apparently, when a file is opened with the open statement, it's not possible to specify a character encoding.
The following simple test VBA program tries to read from a Latin 1, UTF-8 and UTF-16 encoded file.
The files are on github under latin-1.txt, utf-8.txt and utf-16.txt.
option explicit

sub main() ' {

    readFile "latin-1.txt"
    readFile "utf-8.txt"
    readFile "utf-16.txt"

end sub ' }

sub readFile(fileName as string) ' {

   const directoryName$ = "C:\Users\r.nyffenegger\personal\VBA\open-charset\"

   dim f as integer
   f = freeFile()

   open directoryName & fileName for input as #f

   dim txt as string
   line input #f, txt

   debug.print ("Line read from " & fileName & " is: " & txt)

   close f

end sub ' }
Github repository about-VBA, path: /language/statements/open/character-encoding/read-file.bas
When I executed the script, it printed the text from the latin-1.txt and utf-16.txt files correctly while it displayed the text of utf-8 as
Line read from utf-8.txt is: René says: hello

Alternative: Using ADODB to read UTF-8 encoded files

If a UTF-8 file needs to be read in VBA, it seems possible using the ADODB object stream along with loadFromFile.

Index