retrieve text from a text file

T

Tony WONG

i have a vba to retrieve text from a text file. it works fine.

however, when the line of the text file starts with number, like this

2000 Office

then it can only retrieve "2000", not "2000 Office"

how can i retrieve the whole line? Thanks a lot.


*************************************************
Sub StockCount()

Range("A2").Select
Selection.End(xlDown).Select
a = Mid(ActiveCell.Address, 4)
Range("A2:b" & a).Select
Selection.ClearContents

filepath = ThisWorkbook.Path
Set objFSO = New FileSystemObject
Set objFolder = objFSO.GetFolder(filepath)
i = 1
For Each objFile In objFolder.Files
If objFile.Type = "TSV ÀÉ®×" Then
KKK = FreeFile
Open objFile For Input As KKK
Do Until EOF(KKK)
Input #KKK, ABC
If Len(ABC) > 0 And Left(ABC, 4) <> "Comp" And Left(ABC,
4) <> "Disp" And Left(ABC, 4) <> "User" And Left(ABC, 4) <> "Date" Then
i = i + 1
Cells(i, 1) = Left(objFile.Name, InStr(objFile.Name,
".") - 1)
Cells(i, 2) = ABC
End If
Loop
Close
End If
Next

End Sub
 
A

Anand.V.V.N

Hello,
I am not sure if this could be the reason, but might be it could be the
problem with the space character, can you check if there is no space between
the the two words is it able to retrive the whole line. For example if there
is no sapce between the numeric value and the string i.e. instead of 2000
office if its 2000office, will it retrive the whole line?
Hope this was helpful
 
R

Ron Rosenfeld

i have a vba to retrieve text from a text file. it works fine.

however, when the line of the text file starts with number, like this

2000 Office

then it can only retrieve "2000", not "2000 Office"

how can i retrieve the whole line? Thanks a lot.

I believe this shows another reason to use the strongly recommended practice of
Option Explicit and DIMing your variables.

Somewhere near the beginning, enter this:

DIM ABC as string
--ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top