‘订单生成系统.xls
‘f6-第6列,f2-第2列
Private Sub Worksheet_Activate()
On Error Resume Next
Dim x As Object, yy As Object, sql As String
Set x = CreateObject("ADODB.Connection")
x.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;hdr=no;';Data Source=" & ActiveWorkbook.FullName
sql = "select f6,f2,f3,f4,f5,f7,f13,f24 -f25 from [sheet1$] where f24 -f25<f17 and (f13<>'C3' or f13 is null)" ‘不等于字符串用 ‘C3’ 包含空值用 is null
Set yy = x.Execute(sql)
Range("a:h").ClearContents
Range("a1:h1") = Array("编号", "品名", "规格", "产地", "单位", "件装", "属性", "计划") ‘表头 另外赋值
[a2].CopyFromRecordset yy
Set yy = Nothing
Set x = Nothing
End Sub
2,用ADO Connection对象查询