Excel VBA_ADO+SQL实例集锦.doc.txt

时间:2024-04-02 04:55:12
【文件属性】:

文件名称:Excel VBA_ADO+SQL实例集锦.doc.txt

文件大小:93KB

文件格式:TXT

更新时间:2024-04-02 04:55:12

ExcelVBA vba_ado数据库连接

‘订单生成系统.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'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对象查询


网友评论