Sub 账单()

Application.ScreenUpdating = False
Application.DisplayAlerts = False
t = Timer
Dim wb As Workbook
Set wb = ThisWorkbook

With ActiveSheet
    x = .[z11]: y = .[z14]
    If Not IsNumeric(x) Or Not IsNumeric(y) Then GoTo 100
    If x > y Then GoTo 100
    
    ' ? 设置打印区域
    .PageSetup.PrintArea = "R3:W17"
    
    ' ? 设置打印机
    Application.ActivePrinter = "OKI KS4132(PCL6) 在 Ne00:"
    
    ' ? 设置页边距(单位:厘米)
    With .PageSetup
        .LeftMargin = Application.CentimetersToPoints(8.2)
        .RightMargin = Application.CentimetersToPoints(0)
        .TopMargin = Application.CentimetersToPoints(1.5)
        .BottomMargin = Application.CentimetersToPoints(1.5)
        .HeaderMargin = Application.CentimetersToPoints(0.8)
        .FooterMargin = Application.CentimetersToPoints(0.8)
    End With
    
    ' ? 打印确认对话框
    If MsgBox("是否确认开始打印编号从 " & x & " 到 " & y & "?", vbYesNo + vbQuestion, "确认打印") = vbNo Then
        GoTo 100
    End If
    
    ' ? 循环打印编号
    For i = x To y
        .[y1] = i
        .PrintOut
    Next
End With

100:

Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox "共耗时:" & Format(Timer - t, "0.0000") & " 秒!!!", 64

End Sub

Sub 信封()

Application.ScreenUpdating = False
Application.DisplayAlerts = False
t = Timer
Dim wb As Workbook
Set wb = ThisWorkbook

With ActiveSheet
    x = .[z11]: y = .[z14]
    If Not IsNumeric(x) Or Not IsNumeric(y) Then GoTo 100
    If x > y Then GoTo 100
    
    ' ? 设置打印区域
    .PageSetup.PrintArea = "r23:z30"
    
    ' ? 设置打印机
    Application.ActivePrinter = "OKI KS4132(PCL6) 在 Ne00:"
    
    ' ? 设置页边距(单位:厘米)
    With .PageSetup
        .LeftMargin = Application.CentimetersToPoints(0)
        .RightMargin = Application.CentimetersToPoints(0)
        .TopMargin = Application.CentimetersToPoints(0)
        .BottomMargin = Application.CentimetersToPoints(0)
        .HeaderMargin = Application.CentimetersToPoints(0)
        .FooterMargin = Application.CentimetersToPoints(0)
    End With
    
    ' ? 打印确认对话框
    If MsgBox("是否确认开始打印编号从 " & x & " 到 " & y & "?", vbYesNo + vbQuestion, "确认打印") = vbNo Then
        GoTo 100
    End If
    
    ' ? 循环打印编号
    For i = x To y
        .[y1] = i
        .PrintOut
    Next
End With

100:

Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox "共耗时:" & Format(Timer - t, "0.0000") & " 秒!!!", 64

End Sub

Sub 查看当前打印机()

MsgBox Application.ActivePrinter

End Sub

标签: none

添加新评论