2,503
社区成员




Sub test()
Dim i As Integer
Dim nPerCol As Integer
Dim textline As String
Dim strTemp As String
Open "d:\log.txt" For Input As #1
i = 1
While Not EOF(1)
Line Input #1, textline
strTemp = textline
nPerCol = 1 '默认从第一列开始写
Do Until InStr(strTemp, vbTab) = 0 '判断是否含有Tab键
If InStr(strTemp, vbTab) = 1 Then
If Len(strTemp) > 1 Then
strTemp = Right(strTemp, Len(strTemp) - 1) '去掉第一个Tab
Else
strTemp = ""
End If
Else
Cells(i, nPerCol) = Left(strTemp, InStr(strTemp, vbTab) - 1)
strTemp = Right(strTemp, Len(strTemp) - InStr(strTemp, vbTab) + 1)
End If
nPerCol = nPerCol + 1 '无论是去掉一个Tab 还是写入一个值,默认写入列+1
Loop
If Len(strTemp) > 0 Then
Cells(i, nPerCol).Value = strTemp
End If
i = i + 1
Wend
Close #1
End Sub