prdufresne
12-09-2010, 08:56 PM
I'm writing some VBA code to open a text file (.txt), read and parse the contents line by line to isolate some data that will be used to populate a spreadsheet in Excel.
The program hasn't progressed very far, because my initial test code was failing to read the text files I need to work with. If I cut and paste the contents into a new file, it would read it, so I decided to compare the two files with a HEX editor only to discover that the original file is using 16 bits per character (I assume UTF-16, but I don't know for sure).
Sample Hex from the start of the file:
ff fe 46 00 75 00 6c 00 6c 00
Notepad handles the file without trouble. It does't show the first two bytes, but shows the next 8 as the word Full.
Even when I set my file handling to use UTF, it fails to read the file.
How can I get VBA to read this file correctly? I'm using the OpenTextFile and ReadLine methods as in the following sample:
fn = SelectFile() ' Calls a function that allows the user to select a file
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(fn, ForReading, -1)
Response = MsgBox(fn)
ALine = f.ReadLine
Response = MsgBox(ALine)
Any suggestions on how to read this file line by line?
ThanX!
The program hasn't progressed very far, because my initial test code was failing to read the text files I need to work with. If I cut and paste the contents into a new file, it would read it, so I decided to compare the two files with a HEX editor only to discover that the original file is using 16 bits per character (I assume UTF-16, but I don't know for sure).
Sample Hex from the start of the file:
ff fe 46 00 75 00 6c 00 6c 00
Notepad handles the file without trouble. It does't show the first two bytes, but shows the next 8 as the word Full.
Even when I set my file handling to use UTF, it fails to read the file.
How can I get VBA to read this file correctly? I'm using the OpenTextFile and ReadLine methods as in the following sample:
fn = SelectFile() ' Calls a function that allows the user to select a file
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(fn, ForReading, -1)
Response = MsgBox(fn)
ALine = f.ReadLine
Response = MsgBox(ALine)
Any suggestions on how to read this file line by line?
ThanX!