|
楼主 |
发表于 2024-4-18 22:24
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Option Explicit
- Dim Rst As New ADODB.Recordset
- Dim i%, j%
- Private Sub UserForm_Initialize()
- Set Rst = cnn.Execute("Select Distinct 单号 From [列表$A:N]")
- Do While Not Rst.EOF
- ListBox1.AddItem Rst.Fields("单号")
- Rst.MoveNext
- Loop
- Set Rst = Nothing
- Sheets("打印页").Select
- End Sub
- Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
- Set Rst = Nothing
- End Sub
- Private Function cnn() As Object
- Set cnn = CreateObject("adodb.connection")
- If Application.Version < 12 Then
- cnn.Provider = "Microsoft.jet.OLEDB.4.0;Extended Properties=Excel 8.0"
- Else
- cnn.Provider = "Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0"
- End If
- cnn.Open ThisWorkbook.FullName
- End Function
- Private Sub cmd打印_Click()
- For i = 1 To SpinButton1.Max
- SpinButton1.Value = i
- Call PrintOutView(i)
- 'Range("A1:G17").PrintOut '打印指定区域
- Next
- End Sub
- Private Sub cmd全部打印_Click()
- For j = 0 To ListBox1.ListCount - 1
- DoEvents
- ListBox1.Selected(j) = True
- Call cmd打印_Click
- Next
- End Sub
- Private Sub ListBox1_Click()
- If Rst.State <> 0 Then Rst.Close
- Set Rst = CreateObject("adodb.Recordset")
- Rst.Open "Select * FROM [列表$A:N] Where str(单号)='" & Str(ListBox1.Text) & "'", cnn, 1, 3
- Rst.PageSize = 9 '每页条数
- SpinButton1.Max = Rst.PageCount
- SpinButton1.Value = 1
- Call SpinButton1_Change
- End Sub
- Private Sub SpinButton1_Change()
- Rst.AbsolutePage = SpinButton1.Value
- Label1.Caption = "该单有" & Rst.RecordCount & "条记录,分" & Rst.PageCount & "页打印。第" & SpinButton1.Value & "页。"
- Call PrintOutView(SpinButton1.Value)
- End Sub
- Private Sub PrintOutView(Optional ByVal Intex As Integer = 1)
- Dim Temp(1 To 10, 1 To 7), n%
- Rst.MoveLast
- Rst.AbsolutePage = Intex
- n = 0
- Range("B3") = Rst.Fields("日期")
- Range("B4") = Rst.Fields("部门")
- Range("F3") = Rst.Fields("单号")
- Range("F4") = Rst.Fields("出库类别")
- Range("B17,D17,G17") = ""
- If Not IsNull(Rst.Fields("制单人")) Then Range("B17") = Rst.Fields("制单人")
- If Not IsNull(Rst.Fields("审核人")) Then Range("D17") = Rst.Fields("审核人")
- If Not IsNull(Rst.Fields("领料人")) Then Range("G17") = Rst.Fields("领料人")
-
- Do While Not Rst.EOF And n < 9
- n = n + 1
- Temp(n, 1) = Rst.Fields("存货编码")
- Temp(n, 2) = Rst.Fields("存货名称")
- Temp(n, 3) = Rst.Fields("规格型号")
- Temp(n, 4) = Rst.Fields("单位")
- Temp(n, 5) = Rst.Fields("数量")
- Temp(n, 6) = Rst.Fields("仓库")
- Temp(n, 7) = Rst.Fields("生产订单号")
- Rst.MoveNext
- Loop
- Range("A6:G15") = Temp
- End Sub
复制代码
|
|