Skip to content

Instantly share code, notes, and snippets.

@Liyuu8
Created August 3, 2019 11:11
Show Gist options
  • Save Liyuu8/1eb95f4c13547eac13ec67de4da100f7 to your computer and use it in GitHub Desktop.
Save Liyuu8/1eb95f4c13547eac13ec67de4da100f7 to your computer and use it in GitHub Desktop.
Sub Pagebreak()
Dim cl As HPageBreak
Dim ws As Worksheet
Dim shp As Shape
Dim rng As Range
Dim flg As Boolean
For Each cl In ActiveSheet.HPageBreaks
printColCount = ActiveSheet.Range(Sheets("Sheet1").PageSetup.PrintArea).Columns.Count
Debug.Print ("列数=" & printColCount)
'
If Not ActiveSheet.Cells(cl.Location.Row, Cells(cl.Location.Row, printColCount).End(xlToLeft).Column).Value = "" Then
ActiveSheet.Cells(cl.Location.Row, Cells(cl.Location.Row, printColCount).End(xlToLeft).Column).Select
Do Until ActiveCell.Offset(-1, 0).Value = ""
ActiveCell.Offset(-1, 0).Select
Loop
Dim iRow
iRow = ActiveCell.Row
Range("A" & iRow).Pagebreak = xlManual
End If
Set rng = ActiveSheet.Cells(cl.Location.Row, 5)
'
For Each shp In ActiveSheet.Shapes
If Intersect(ActiveSheet.Range(shp.TopLeftCell, shp.BottomRightCell), rng) Is Nothing = False Then
shp.TopLeftCell.Select
Dim iRow2
iRow2 = ActiveCell.Row
Range("A" & iRow2).Pagebreak = xlManual
End If
Next
Next cl
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment