返回列表 上一主題 發帖

[發問] 有關停止printout的問題

回復 1# yuan5447
  1. If 條件 = "成立" Then Sheet1.PrintOut
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 4# yuan5447
是這樣嗎?
  1. Option Explicit
  2. Sub Ex()
  3.     Dim PrintMonTh As String, Rng(1 To 2) As Range, i As Integer, ii As Integer
  4.     PrintMonTh = Format(DateAdd("M", -1, Date), "M月")  '上一月份
  5.     PrintMonTh = InputBox("請輸入月份", , PrintMonTh)   '輸入正確月份
  6.     If Val(PrintMonTh) <= 0 Or Mid(PrintMonTh, Len(PrintMonTh)) <> "月" Then GoTo ER '
  7.     'Val(PrintMonTh) <= 0 : 數字>0 , Mid(PrintMonTh, Len(PrintMonTh)) <> "月":最後的字元<>"月"
  8.     On Error GoTo ER   '輸入的月份工作表不存在,下面的程式碼會有錯誤
  9.     With Sheets("薪資單列印")
  10.         Set Rng(1) = .Range("C4:C21")    '第一筆輸入資料的範圍
  11.         .PageSetup.PrintArea = .Range("a4:k21").Address   '印列範圍的設定
  12.     End With
  13.     With Sheets(PrintMonTh)  ' . 為這物件(工作表)下的物件,方法,屬性
  14.         i = 5
  15.         ii = 0
  16.         Do While .Cells(i, "A") <> ""       '這物件(工作表)下的A欄<>""
  17.             If .Cells(i, "A") <> "管理" Then
  18.                 Set Rng(2) = Rng(1).Offset(, ii * 4)   'ii * 4 : Rng(1)位移的欄數,移到下一筆要輸入的位置
  19.                 Rng(2).Cells(1) = PrintMonTh     '月份
  20.                 Rng(2).Cells(2) = .Cells(i, "B") '姓名
  21.                 Rng(2).Cells(3) = .Cells(i, "P") '本奉
  22.                 Rng(2).Cells(4) = .Cells(i, "Q") '日新
  23.                 Rng(2).Cells(5) = .Cells(i, "C") '天數(出勤日數)
  24.                 Rng(2).Cells(6) = .Cells(i, "Q") * .Cells(i, "C")
  25.                                                  '小計 (天數*日新)
  26.                 Rng(2).Cells(7) = .Cells(i, "R") '工作津貼
  27.                 Rng(2).Cells(8) = .Cells(i, "S") '證照費
  28.                 Rng(2).Cells(9) = .Cells(i, "U") '伙食津貼
  29.                 Rng(2).Cells(10) = .Cells(i, "T") '加班費
  30.                 Rng(2).Cells(11) = .Cells(i, "L") '節慶獎金
  31.                 Rng(2).Cells(12) = .Cells(i, "V") '請假扣款
  32.                 Rng(2).Cells(13) = .Cells(i, "W") '遲到扣款
  33.                 Rng(2).Cells(14) = .Cells(i, "X") '勞保費
  34.                 Rng(2).Cells(15) = .Cells(i, "T") '健保費
  35.                 Rng(2).Cells(16) = .Cells(i, "Z") '勞退金
  36.                
  37.                 Rng(2).Cells(18) = .Cells(i, "AB") '實領金額
  38.                 If ii = 2 Then  '達 3人次
  39.                     Sheets("薪資單列印").PrintOut
  40.                     For ii = 0 To 2       '清除資料
  41.                         Rng(1).Offset(, ii * 4) = ""
  42.                     Next
  43.                     ii = 0     '次數:歸零
  44.                 Else
  45.                     ii = ii + 1
  46.                 End If
  47.             End If
  48.             i = i + 1
  49.         Loop
  50.     End With
  51.     MsgBox "印列 完畢"
  52.     Exit Sub
  53. ER:
  54.     MsgBox "沒有 " & IIf(PrintMonTh = "", "輸入月份", PrintMonTh & " 工作表")
  55. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 一個人的快樂.不是因為他擁有得多,而是因為他計較得少。
返回列表 上一主題