|
Sub limonet()
Dim Cn As Object, StrSQL$, Arr As Variant, i%, j%, k%, Rst As Object, Brr As Variant
Set Cn = CreateObject("Adodb.Connection")
Set Rst = CreateObject("adodb.recordset")
Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
Arr = Cn.Execute("Select Distinct 出库单号 From [领料$]").GetRows
For i = 0 To UBound(Arr, 2)
Sheets("Template").Copy Before:=Sheets(Sheets.Count)
ActiveSheet.Name = Arr(0, i)
StrSQL = " From [领料$] Where 出库单号='" & Arr(0, i) & "'"
Brr = Cn.Execute("Select 出库单号,业务号,出库日期,出库类别,项目名称" & StrSQL).GetRows(1)
[L5].Value = Brr(0, 0): [C6] = Brr(1, 0): [G6] = Brr(2, 0): [L6] = Brr(3, 0): [C7] = Brr(4, 0)
Rst.Open "Select 材料编码,材料名称,规格型号,Null,Null,Null,Null,Null,Null,主计量单位,数量" & StrSQL, Cn, 1, 3
If Rst.RecordCount < 14 Then Rows((Rst.RecordCount + 9) & ":22").Delete
Range("B9").CopyFromRecordset Rst: Rst.Close
Next i
End Sub
|
|