|
- Sub ReadFile()
- Dim iFile As Integer
- iFile = FreeFile
- Dim sLine As String
- Dim iRow As Integer
- Sheet2.Cells(1, 2) = "TOTNSUB"
- Sheet2.Cells(1, 3) = "TOTNSUBA"
- iRow = 1
- Open ThisWorkbook.Path & "\文本.TXT" For Input As iFile
- While Not EOF(iFile)
- Line Input #iFile, sLine
- sLine = Trim(sLine)
- If Left(sLine, 3) = "eaw" Then
- iRow = iRow + 1
- Sheet2.Cells(iRow, 1) = Right(sLine, Len(sLine) - 4)
- ElseIf sLine = "TOTNSUB" Then
- Line Input #iFile, sLine
- Sheet2.Cells(iRow, 2) = sLine
- ElseIf sLine = "TOTNSUBA" Then
- Line Input #iFile, sLine
- Sheet2.Cells(iRow, 3) = sLine
- End If
- Wend
- Close iFile
- End Sub
复制代码 如果需要求出的都是TOTNSUB和TOTNSUBA这两项的话,就可以用这个搞定了。
其中数据的“文本.txt”要和EXCEL文件在同一目录里
|
|