例如簡單的從sheet1表中的數據取到表二:
Sub 簡單查詢()
Set cn = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")
cn.Open "provider=microsoft.jet.oledb.4.0;Extended Properties='Excel 8.0';data source=" & ThisWorkbook.FullName
Sql = "select * from [sheet1$]"
Sheets(2).[A2].CopyFromRecordset cn.Execute(Sql)
MsgBox "取數據成功"
Sheets("sheet2").Select
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
例如簡單的從sheet1表中的數據取到表二: Sub 簡單查詢() Set cn = CreateObject("adodb.connection") Set rs = CreateObject("adodb.recordset") cn.Open "provider=microsoft.jet.oledb.4.0;Extended Properties='Excel 8.0';data source=" & ThisWorkbook.FullName Sql = "select * from [sheet1$]" Sheets(2).[A2].CopyFromRecordset cn.Execute(Sql) MsgBox "取數據成功" Sheets("sheet2").Select cn.Close Set rs = Nothing Set cn = Nothing End Sub