Board logo

標題: [發問] 如何得到當前列印範圍頁數? [打印本頁]

作者: naruto018    時間: 2017-4-5 10:56     標題: 如何得到當前列印範圍頁數?

如何得到當前列印範圍頁數?
我想要在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
複製代碼

作者: 准提部林    時間: 2017-4-9 10:47

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




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)