|
- Sub test1()
- Dim srcFile As String
- With Application.FileDialog(msoFileDialogOpen)
- .InitialFileName = ThisWorkbook.Path
- With .Filters
- .Clear
- .Add "Excel Files", "*.xls?"
- End With
- .AllowMultiSelect = False
- If .Show Then srcFile = .SelectedItems(1) Else Exit Sub
- End With
-
- Dim Conn As Object, SQL As String
-
- SQL = "SELECT F5,F45,F3,F44,F39,F98,F83,F241,F42,F236,F8,F128,F116,F119,F220,F197 FROM [$A2:IV]"
-
- Set Conn = CreateObject("ADODB.Connection")
- Conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=no';Data Source=" & srcFile
-
- With Range("A5")
- .Resize(Rows.Count - .Row, Columns.Count).ClearContents
- .CopyFromRecordset Conn.Execute(SQL)
- End With
-
- Conn.Close
- Set Conn = Nothing
- Beep
- End Sub
复制代码 |
|