|
Re: Getting text file into a VBA string variable
Sub Tester4()
Dim fname As String
Dim sVal As String
fname = "C:\xlText\MyText.txt"
sVal = OpenTextFileToString2(fname)
Debug.Print sVal
End Sub
Function OpenTextFileToString2(ByVal strFile As String) As String
' RB Smissaert - Author
Dim hFile As Long
hFile = FreeFile
Open strFile For Input As #hFile
OpenTextFileToString2 = Input$(LOF(hFile), hFile)
Close #hFile
End Function
Produced:
this is line 1
This is line 2
This is line 3
This is line 4
which is what was in the text file.
..
--
Regards,
Tom Ogilvy
"Don Wiss" <donwiss@no_spam.com> wrote in message
news:pfuot05mk3f4trsar5brq0n7n1moj4usrr@4ax.com...
> I'd like to read a short text string in from the hard disk and assign it
to
> a VBA string variable. I hunted around in the VBA help file, and couldn't
> find anything on getting files. I don't want to open a file and put it
onto
> a Worksheet and then read it from there. (And then close the Sheet.) A bit
> of overkill for a four character long file.
>
> Don <donwiss at panix.com>.
|