Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. Sub Pagebreak()
  2.  
  3. Dim cl As HPageBreak
  4. Dim ws As Worksheet
  5. Dim shp As Shape
  6. Dim rng As Range
  7. Dim flg As Boolean
  8. Dim loopCount As Integer: loopCount = 1
  9.  
  10. Do While ActiveSheet.HPageBreaks.Count + 1 <> loopCount
  11. Set cl = ActiveSheet.HPageBreaks(loopCount)
  12.  
  13. printColCount = ActiveSheet.Range(Sheets("Sheet1").PageSetup.PrintArea).Columns.Count
  14. Debug.Print ("改ページ=" & ActiveSheet.HPageBreaks.Count)
  15.  
  16. '
  17. If Not ActiveSheet.Cells(cl.Location.Row, Cells(cl.Location.Row, printColCount).End(xlToLeft).Column).Value = "" Then
  18.  
  19. ActiveSheet.Cells(cl.Location.Row, Cells(cl.Location.Row, printColCount).End(xlToLeft).Column).Select
  20.  
  21. Do Until ActiveCell.Offset(-1, 0).Value = ""
  22. ActiveCell.Offset(-1, 0).Select
  23.  
  24. Loop
  25. Dim iRow
  26. iRow = ActiveCell.Row
  27.  
  28. Range("A" & iRow).Pagebreak = xlManual
  29. End If
  30.  
  31.  
  32. Set rng = ActiveSheet.Cells(cl.Location.Row, 5)
  33. '
  34. For Each shp In ActiveSheet.Shapes
  35. If Intersect(ActiveSheet.Range(shp.TopLeftCell, shp.BottomRightCell), rng) Is Nothing = False Then
  36.  
  37. shp.TopLeftCell.Select
  38.  
  39. Dim iRow2
  40. iRow2 = ActiveCell.Row
  41.  
  42. Range("A" & iRow2).Pagebreak = xlManual
  43.  
  44. End If
  45. Next
  46.  
  47. loopCount = loopCount + 1
  48. Loop
  49. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement