|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Option Explicit
- Sub test0() '
-
- Dim Files_ As FileDialogSelectedItems
-
- With Application.FileDialog(msoFileDialogFilePicker)
- .InitialFileName = ThisWorkbook.Path
- With .Filters
- .Clear
- .Add "Excel Files", "*.xls*"
- End With
- .AllowMultiSelect = True
- If .Show Then Set Files_ = .SelectedItems Else Exit Sub
- End With
-
- Cells.ClearContents
- DoApp False
-
- Dim File_, j As Long, s As String
- Dim Conn As Object, strConn As String, strSQL As String
- Set Conn = CreateObject("ADODB.Connection")
-
- s = "Excel 12.0;HDR=NO;Database="
- If Application.Version < 12 Or InStr(Application.Path, "WPS") > 0 Then
- s = Replace(s, "12.0", "8.0")
- strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=NO';Data Source="
- Else
- strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=NO';Data Source="
- End If
-
-
- j = 1
- strSQL = "SELECT * FROM [" & s & "[.File_]].[$A:IV]"
- For Each File_ In Files_
- If ThisWorkbook.FullName <> File_ Then
- If Conn.State <> 1 Then Conn.Open strConn & File_
- Cells(1, j).CopyFromRecordset Conn.Execute(Replace(strSQL, "[.File_]", File_))
- j = Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).Column
- j = j - (j > 1) * 2
- End If
- Next
-
- Set Files_ = Nothing
- If Conn.State = 1 Then Conn.Close
- Set Conn = Nothing
-
- DoApp
- Beep
- End Sub
- Function DoApp(Optional b As Boolean = True)
- With Application
- .ScreenUpdating = b
- .DisplayAlerts = b
- .Calculation = -b * 30 - 4135
- End With
- End Function
复制代码 |
评分
-
2
查看全部评分
-
|