1个回答
展开全部
假设你的文件名为:textfile.txt,并在"我的文档"里面
Sub ImportRange()
Dim ImpRng As Range
Dim Filename As String
Dim r As Long, c As Integer
Dim txt As String, Char As String * 1
Dim Data
Dim i As Integer
Set ImpRng = ActiveCell
On Error Resume Next
Filename = Application.DefaultFilePath & "\textfile.txt"
Open Filename For Input As #1
If Err <> 0 Then
MsgBox "Not found: " & Filename, vbCritical, "ERROR"
Exit Sub
End If
r = 0
c = 0
txt = ""
Application.ScreenUpdating = False
Do Until EOF(1)
Line Input #1, Data
For i = 1 To Len(Data)
Char = Mid(Data, i, 1)
If Char = Chr(9) Then
ActiveCell.Offset(r, c) = txt
c = c + 1
txt = ""
ElseIf i = Len(Data) Then
ActiveCell.Offset(r, c) = txt
txt = ""
Else
txt = txt & Char
End If
Next i
c = 0
r = r + 1
Loop
Close #1
Application.ScreenUpdating = True
End Sub
更多追问追答
追问
批量?三列?
追答
有多少文件?最好看到你的文件,不然不知道读取的效果
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询