Created
August 6, 2019 12:04
-
-
Save Liyuu8/86b4539ad53dbf8855765f75384c61a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Pagebreak() | |
Dim cl As HPageBreak | |
Dim ws As Worksheet | |
Dim shp As Shape | |
Dim rng As Range | |
Dim flg As Boolean | |
Dim loopCount As Integer: loopCount = 1 | |
Do While ActiveSheet.HPageBreaks.Count + 1 <> loopCount | |
Set cl = ActiveSheet.HPageBreaks(loopCount) | |
printColCount = ActiveSheet.Range(Sheets("Sheet1").PageSetup.PrintArea).Columns.Count | |
Debug.Print ("改ページ=" & ActiveSheet.HPageBreaks.Count) | |
' | |
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 | |
loopCount = loopCount + 1 | |
Loop | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment