|
- Sub Test1()
- Dim i&, j&, x&, Arr, Nrr(), Wk As Workbook
- Dim Conn, Reco1, Reco2, SQL$, Table
- Application.ScreenUpdating = False
- With Application.FileDialog(3) '
- .AllowMultiSelect = True '
- .Filters.Clear
- .Filters.Add "Excel File", "*.xls*"
- If .Show = -1 Then
- ReDim Nrr(1 To .SelectedItems.Count)
- For i = 1 To .SelectedItems.Count
- Nrr(i) = .SelectedItems(i)
- Next i
- End If
- End With
- If i = 0 Then Exit Sub
- Set Wk = ThisWorkbook
- Set Conn = CreateObject("adodb.connection")
- Set Reco1 = CreateObject("adodb.recordset")
- Set Reco2 = CreateObject("adodb.recordset")
- x = 1
- For i = 1 To UBound(Nrr)
- Conn.Open "provider=Microsoft.ACE.OLEDB.12.0;extended properties='excel 12.0;hdr=no;imex=1';Data Source = " & Nrr(i)
- Set Reco1 = Conn.OpenSchema(20)
- Do Until Reco1.EOF
- If Reco1.Fields("TABLE_TYPE") = "TABLE" Then
- Table = Reco1("TABLE_NAME").Value
- If Right(Table, 1) = "$" Or Right(Table, 2) = "$'" Then
- Table = "[" & Table & "]"
- SQL = "select * from " & Table
- Reco2.Open SQL, Conn, 1, 1
- Arr = Reco2.getrows
- Wk.Sheets(1).Range("a" & x).Resize(UBound(Arr, 2), UBound(Arr)) = WorksheetFunction.Transpose(Arr)
- x = x + UBound(Arr, 2)
- Reco2.Close
- Erase Arr
- End If
- End If
- Reco1.MoveNext
- Loop
- Conn.Close
- Next i
- Application.ScreenUpdating = True
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|