i need to open a txt file and read it into a string in VBA, but i would like to only get the first 1000 characters.
the file itself is 20mb and i only need the first 1000 characters. is there a way to make this efficient?
i need to open a txt file and read it into a string in VBA, but i would like to only get the first 1000 characters.
the file itself is 20mb and i only need the first 1000 characters. is there a way to make this efficient?
How long is each of the lines in the file. What I would do is either read it in by character or by line (if the lines are shorter) and then set a cap of 1000 characters. This way you don't have to read in the whole file. You just read the first 1000 characters or a bit more if you are reading it in line by line.
Not sure if there is a more efficient way, but this method is pretty simple:
Dim sText As String
Open "C:\myfile.txt" For Input As #1
sText = Input$(1000, 1)
Close #1