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
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