View Single Post
  #5  
Old 01-05-2005, 08:06 PM
Don Wiss
Guest
 
Posts: n/a
Re: Getting text file into a VBA string variable

On 5 Jan 2005, Francis Ang <FrancisAng@discussions.microsoft.com> wrote:

>Try this
>
>Open "C:\Myfile.txt" for input as #1
> Input #1, ShortText
>Close #1
>
>Mystring=ShortText


This works fine for my first use. But then I was trying to read in a
multi-line file, where each line is delimited by a NL/LF pair. (Which makes
it really just a vector in the file.) But the input just gets the first
line. Adding Do While Not EOF and concatenating each string (with NL/LFs)
has two problems: (1) There are commas in the text that are not delimiters,
and (2) it strips away leading blanks in the front of each line. Now I
could create a file with double quotes around each line, but this is an
existing txt file that I'd like to still be readable in Notepad.

I suspect the answer for this is to use the Get statement. But when I try
this I get a Run-time error '54': Bad file mode.

Don <donwiss at panix.com>.
Reply With Quote