返回列表 上一主題 發帖

[發問] 如何得到當前列印範圍頁數?

[發問] 如何得到當前列印範圍頁數?

如何得到當前列印範圍頁數?
我想要在VBA中間加入判斷當前列印範圍頁數是否超過2頁
  1. Public Sub 列印()
  2. With Worksheets("1111")
  3. .PageSetup.PrintArea = .Range(Cells(1, 1), Cells(Rows.Count, 9)).Address '設定列印範圍

  4. '<---加入判斷頁面是否超過2頁
  5. MyPage = 1 '<---獲得當前列印範圍頁數
  6. If MyPage > 2 Then '<---判斷當前列印範圍頁數
  7. MsgBox "頁面超過2頁,請重新調整頁面,再列印"
  8. Else
  9. .PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False '列印
  10. End If
  11. End With
  12. End Sub
複製代碼

HP = ActiveSheet.HPageBreaks.Count + 1 '縱向頁數
VP = ActiveSheet.VPageBreaks.Count + 1 '橫向頁數
PG = HP * VP '總頁數

TOP

        靜思自在 : 【是否發揮了良能?】人間壽命因為短暫,才更顯得珍貴。難得來一趟人間,應問是否為人間發揮了自己的良能,而不要一味求長壽。
返回列表 上一主題