We receive a file from a third party and need to read it in. I'm getting an error 62 due to corruption/characters in their file. I've attached a very small file showing the current character causing problems. Is there any way I can get past this? At the moment I'm manually opening the file and deleting the character(s), but that's not acceptable.
Private Sub doImportFile()
ImportFile "H:\dat.txt", ""
Private Function ImportFile(sLoc As String, ByRef Contents As String) As Boolean
On Error GoTo onExcept
Dim vff As Long
Dim lngChars As Long
Dim sLine As String
Dim sStr As String
vff = FreeFile
Open sLoc For Input As #vff
lngChars = LOF(vff)
Do Until EOF(vff) 'this only gets up to illegal character in file
Line Input #vff, sLine
sStr = sStr & sLine
sStr= Input(lngChars, vff) 'this throws an error 62
Debug.Print Err.Number & ": " & Err.Description
I've tried the two methods I know as per embedded code. First only gets to '12345', rather than '123456789ABCDEFGHIJ'. I need to read in the whole file, of course. sStr= Input(lngChars, vff)
, it gives an Error 62.
The preferred solution I guess is to be able to parse the contents without getting caught out by the character(s) prematurely signalling EOF, although also I guess can pre-process file to remove? Any advice welcome!