"rd="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet O" _
, "LEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False"), Destination _
:=Range("A1"))
.CommandType = xlCmdTable
.CommandText = Array("select * from [Sheet1$] a left join [Sheet2$] b on a.訂單編號=b.訂單編號")
.Name = "data_3"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = "F:\data.xls"
.Refresh BackgroundQuery:=False
End With
End Sub
複製代碼
=====================
SQL語法範例
select * from [Sheet1$] where 訂單編號='A002'
select * from [Sheet1$] where 送貨備註='需回收禮卷'
select * from [Sheet1$] where 送貨備註='需回收禮卷' and 總金額=0
select * from [Sheet1$] a left join [Sheet2$] b on a.訂單編號=b.訂單編號
select * from [Sheet1$] a left join [Sheet2$] b on a.訂單編號=b.訂單編號 where a.訂單編號='A002'