从txt提取指定位置数据到excel中的VBA,本人不懂代码,请问下面代码那里是修改txt档位置
Sub读取Txt()DimcPath$,nL%,cFile$,Arr,BrrcPath=ThisWorkbook.Path&"\"cFile=Dir(cPath&"*.t...
Sub 读取Txt()
Dim cPath$, nL%, cFile$, Arr, Brr
cPath = ThisWorkbook.Path & "\"
cFile = Dir(cPath & "*.txt")
nL = 2
Application.ScreenUpdating = False
Application.EnableEvents = False
Intersect(Me.Range("2:1048576"), Me.UsedRange).ClearContents
Do While cFile <> ""
Open cPath & cFile For Input As #1
Arr = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf)
Cells(2, nL).Resize(1, 2).Value = Array("Name", "NO.")
For i = 5 To UBound(Arr)
Arr(i) = Replace(Arr(i), ",", ",")
If Arr(i) Like "*,*,*" Then
Brr = Split(Replace(Arr(i), ",", ","), ",")
Cells(i - 2, nL).Value = Brr(1)
Cells(i - 2, nL + 1).Value = Brr(2)
End If
Next
Close #1
cFile = Dir
nL = nL + 3
Loop
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
修改提取TXT档中数据的位置,不是TXT档 的位置 展开
Dim cPath$, nL%, cFile$, Arr, Brr
cPath = ThisWorkbook.Path & "\"
cFile = Dir(cPath & "*.txt")
nL = 2
Application.ScreenUpdating = False
Application.EnableEvents = False
Intersect(Me.Range("2:1048576"), Me.UsedRange).ClearContents
Do While cFile <> ""
Open cPath & cFile For Input As #1
Arr = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf)
Cells(2, nL).Resize(1, 2).Value = Array("Name", "NO.")
For i = 5 To UBound(Arr)
Arr(i) = Replace(Arr(i), ",", ",")
If Arr(i) Like "*,*,*" Then
Brr = Split(Replace(Arr(i), ",", ","), ",")
Cells(i - 2, nL).Value = Brr(1)
Cells(i - 2, nL + 1).Value = Brr(2)
End If
Next
Close #1
cFile = Dir
nL = nL + 3
Loop
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
修改提取TXT档中数据的位置,不是TXT档 的位置 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询