EXCEL宏实现自动分页的方法

Sub 自动分页()
Dim i%, k%
Application.ScreenUpdating = False
ActiveSheet.ResetAllPageBreaks ‘从论坛高手那学到:在设置之前应该重设所有分页符,避免表格分页符混乱
For i = 13 To 4398
If Cells(i, 7) <> Cells(i – 1, 7) Then
ActiveSheet.HPageBreaks.Add Before:=Cells(i, 1)
‘Cells(i + 1, 1).Select
‘ActiveCell = 1
End If
If Cells(i, 1) = 20 Then
ActiveSheet.HPageBreaks.Add Before:=Cells(i + 1, 1)
‘Cells(i + 1, 1).Select
‘ActiveCell = 1
End If

Next
Application.ScreenUpdating = True

End Sub