Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim xArea As Range
With ActiveSheet
.PageSetup.PrintArea = "" '重設列印範圍
.ResetAllPageBreaks '重設分頁線
If .HPageBreaks.Count Mod 2 = 0 Then '檢測頁數是否為奇數
Set xArea = Range(.[A1], .UsedRange.Offset(1, 0))
xArea.Name = "'" & .Name & "'!Print_Area" '設定列印範圍
.HPageBreaks.Add before:=Rows(xArea.Rows.Count + 1) '加入分頁線
End If
End With
End Sub