|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Option Explicit
- Private Sub ComboBox1_Change() '开始页
- Dim br(), y&
- If ComboBox2.Value < ComboBox1.Value Then
- ComboBox2.Value = ComboBox1.Value
- Me.Label2.Caption = 1
- Else
- Me.Label2.Caption = 1 * ComboBox2.Value - 1 * ComboBox1.Value + 1
- End If
- End Sub
- Private Sub ComboBox2_Change() '终止页
- If ComboBox2.Value < ComboBox1.Value Then
- MsgBox "终止号不能小于开始号!"
- Me.Label2.Caption = 0
- Exit Sub
- Else
- Me.Label2.Caption = 1 * ComboBox2.Value - 1 * ComboBox1.Value + 1
- End If
- End Sub
- Private Sub CommandButton1_Click() '确定
- Dim i%
- If ComboBox1.Value = "" Or ComboBox1.Value = "" Then
- MsgBox "请输入打印的起始序。"
- Exit Sub
- End If
- For i = ComboBox1.Value To ComboBox2.Value
- Range("h7") = Sheets("信息").Cells(i + 1, 2)
- Range("j7") = Sheets("信息").Cells(i + 1, 4)
- ActiveSheet.PrintPreview '打印预览
- ' ActiveSheet.PrintOut '直接打印
- Next
- Unload Me
- End Sub
- Private Sub CommandButton2_Click() '退出
- Unload Me
- End Sub
- Private Sub UserForm_Initialize()
- Dim arr, r%, p%
- r = Sheets("信息").Range("a65536").End(3).Row
- p = Sheets("信息").Cells(r, 1)
- arr = Sheets("信息").Range("A2:A" & r)
- Me.ComboBox1.List = arr
- Me.ComboBox2.List = arr
- Me.Label1.Caption = p
- Me.Label2.Caption = 0
- End Sub
复制代码 |
|