Re: Ues SQL on data in Active Workbook
Code
With Sheet1 .Cells.Clear
Set Cnn = New ADODB.Connection
With Cnn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.ConnectionString = "Extended Properties=Excel 12.0;" _
& "Data Source=" & ThisWorkbook.Path & "\数据.xlsx"
.Open
End With
Set rs = New ADODB.Recordset
Sql = "Select * From [Sheet1$]"
rs.Open Sql, Cnn, adOpenKeyset, adLockOptimistic
For j = 0 To rs.Fields.Count - 1
.Cells(1, j + 1) = rs.Fields(j).Name
Next
r = .Cells(.Rows.Count, 1).End(xlUp).Row
.Range("A" & r + 1).CopyFromRecordset rs
End With
Display More