|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 提取数据()
Application.ScreenUpdating = False
Dim ar As Variant
Dim arr()
Set sh = ThisWorkbook.ActiveSheet
ReDim arr(1 To 90000, 1 To 200)
f = Dir(ThisWorkbook.Path & "\*.txt")
Do While f <> ""
If f <> ThisWorkbook.Name Then
Open ThisWorkbook.Path & "\" & f For Input As #1 ''打开选择的文本文件
n = n + 1
ar = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf) ''把文本文件的数据赋值给数组lines
k = UBound(ar) ' + 1 '文件的行数
'遍历每一行
y = 3
arr(n, 1) = Replace(ar(3), "零件名: ", "")
arr(n, 2) = Replace(f, ".TXT", "")
For i = 9 To k ''循环数组行
If Left(ar(i), 1) <> "" Then
If InStr(ar(i), "MIN") = 0 Then
rr = Split(ar(i), Chr(32))
m = 0
ReDim br(1 To UBound(rr) + 1)
For s = 0 To UBound(rr)
If rr(s) <> "" Then
If IsNumeric(rr(s)) Then
m = m + 1
br(m) = rr(s)
End If
End If
Next s
If m > 1 Then
y = y + 2
arr(n, y - 1) = br(m - 1)
arr(n, y) = br(m)
End If
End If
End If
Next i
Close #1 ''关闭打开的文本文件
End If
f = Dir
Loop
With sh
.[a1].CurrentRegion.Offset(2).Borders.LineStyle = 0
.[a1].CurrentRegion.Offset(2) = Empty
.[a3].Resize(n, 39) = arr
.[a3].Resize(n, 39).Borders.LineStyle = 1
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|