View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rob van Gelder[_4_] Rob van Gelder[_4_] is offline
external usenet poster
 
Posts: 1,236
Default Reading Textfile into a variable

Try: Open SourceFile For Binary As FF

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Seth" wrote in message
...
Hi,

I am trying to use the Input function to read the
contents of a text file into a variable. The text file
is very large, and I keep getting the same message
everytime I try to run code that I know works on other
text files (they are smaller):

"Input past end of file"

Here is the code:
____________________________________________
FF = FreeFile ' get the next free file in line

Open SourceFile For Input As FF ' Opens the text file
stream
lChars = LOF(FF) ' lChars is a LONG varaible

AllText = Input(lChars, FF) ' Loads the textfile into
the AllText variable (AllText is a string variable and i
tried Variant too with the same result)

Close FF
_______________________________________________

The number of characters in the text file is 2,685,277.
When the code is executed i get "Input past end of file".

If I force the number of characters to a lower number, it
all works fine.

Any thoughts on what is going on, and if there is a
workaround?

Thanks,

Seth