• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Delete all the shapes out of print area

YasserKhalil

Well-Known Member
Hello everyone
I need to delete all the shapes out of range of print area .. and keep only shapes within the print area

Thanks advanced for help
 
Do you need those shapes for any reason later?
Why I ask is that they can be made non-printing if they are still required
 
I need to keep the shapes inside the print area and they would be printable ..
And as for other shapes outside (any type of shape) to be deleted
 
This will delete all the shapes not totally within the Print_Area

Code:
Sub Del_Shapes()

'Delete shapes that are not fully inside the Print_Area
Dim aName As String
Dim shp As Shape
Dim myDocument As Worksheet

aName = ActiveSheet.Name
Set myDocument = Worksheets(aName)

For Each shp In Shapes
  If Not Intersect(myDocument.Range("Print_Area"), shp.TopLeftCell) Is Nothing And _
  Not Intersect(myDocument.Range("Print_Area"), shp.BottomRightCell) Is Nothing Then

  'This shape is entirely with the Print_Area
  'Debug.Print shp.ID, shp.BottomRightCell.Address, shp.TopLeftCell.Address

  Else
  shp.Delete

  End If
Next
End Sub
 
Last edited:
This will delete only shapes that are fully outside the Print Area
Shapes that overlap the edges of the print range are left in place

Code:
Sub Del_Shapes()
'Delete shapes that are fully outside the Print_Area

Dim aName As String
Dim shp As Shape
Dim myDocument As Worksheet
Dim tmpRng As String

aName = ActiveSheet.Name
Set myDocument = Worksheets(aName)

For Each shp In Shapes
  tmpRng = shp.TopLeftCell.Address & ":" & shp.BottomRightCell.Address
  If Intersect(myDocument.Range("Print_Area"), myDocument.Range(tmpRng)) Is Nothing Then shp.Delete
Next
End Sub
 
Last edited:
Back
Top