|
首先要把文件名中的pxp 删除,我用的access批量重命名.
奇数,偶数分开两张表。
Option Explicit
Sub a()
Dim cnn As Object, rs As Object, SQL$, Mypath$, MyName$, arr, i, m, K As Integer
Dim brr(1 To 400, 1 To 200), cRR(1 To 400, 1 To 200), J, t As Byte
Mypath = ThisWorkbook.Path & "\"
MyName = Dir(Mypath & "*.TXT")
Application.ScreenUpdating = False
Do While MyName <> ""
If MyName <> ThisWorkbook.Name Then
Set cnn = CreateObject("ADODB.CONNECTION")
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Mypath & ";Extended Properties=""text;HDR=yes;"""
SQL = "Select * From [" & MyName & "]"
arr = cnn.Execute(SQL).GetRows
If Left(MyName, InStr(MyName, ".") - 1) Mod 2 = 0 Then
m = 1: J = J + 1
brr(m, J) = "文件名: " & Left(MyName, InStr(MyName, ".") - 1)
For i = 4 To UBound(arr, 2)
m = m + 1
brr(m, J) = Mid(arr(0, i), 11)
Next
Else
K = 1: t = t + 1
cRR(K, t) = "文件名: " & Left(MyName, InStr(MyName, ".") - 1)
For i = 4 To UBound(arr, 2)
K = K + 1
cRR(K, t) = Mid(arr(0, i), 11)
Next
End If
End If
MyName = Dir
Loop
cnn.Close: Set cnn = Nothing
Sheet1.Cells.Clear
Sheet1.[a1].Resize(400, 200) = brr
Sheet2.Cells.Clear
Sheet2.[a1].Resize(400, t) = cRR
Application.ScreenUpdating = True
End Sub
|
|