I am reading a fairly large text file in VBA. The source file contains various text data from an international conference, and I copy the extracted parts of this data in an organized format to an Excel worksheet. I have posted the main parts of the procedure below. (I am a primitive programmer, so I use primitive methods. Sorry for my poor form.)
The problem is with the arrangement of characters that are not simple ASCII characters. Text files contain various entries, such as "München". When writing an Excel file, the text is badly crippled. In this case, I get "München". What is really annoying is that I can copy text from a text file and paste it into Excel, no problem. But there are too many entries to do this manually. I really want original (non-ASCII) characters written to a spreadsheet!
I spent a lot of time finding a solution, and I found two related threads. Firstly, there is something called "binaryStream" described in the first answer:
Excel VBA - export to UTF-8
This is not quite close to what I'm trying to do, and I cannot figure out which parts I need .
There is also a Save UTF-8 text file encoded using VBA that describes how to write UTF-8 data to a text file. Almost, but I want to write an Excel spreadsheet!
Any suggestions please?
Sub ParseText()
Dim myFile As String, Author1 As String, Author2 As String
Dim dept As String, inst As String, country As String
Dim title As String, LineText As String
Dim nSourceFile As Integer, NewRecord As Boolean
Dim First13 As String, nn As Integer, Row As Integer, LineText2 As String
myFile = Application.GetOpenFilename()
nSourceFile = FreeFile
Open myFile For Input As #nSourceFile
Row = 2
While Not EOF(nSourceFile)
Line Input #nSourceFile, LineText ''This is a blank line
Line Input #nSourceFile, LineText ''This has both first and last name
Author1 = Right(LineText, Len(LineText) - 2)
Author2 = RTrim(Left(Author1, Len(Author1) - 1))
LineText = Author2
nn = InStrRev(LineText, " ")
Author1 = RTrim(Left(LineText, nn))
Author2 = RTrim(Right(LineText, Len(LineText) - nn))
nn = Len(Author2)
LineText = LCase(Right(Author2, nn - 1))
Author2 = Left(Author2, 1) & LineText
Cells(Row, 1) = Author1
Cells(Row, 2) = Author2
Row = Row + 1
Wend '' reached the end of file
End Sub