View Full Version : [SOLVED:] Is it possible to find images in document by size then delete them?
Helen269
06-22-2022, 08:56 PM
I have several documents that have images throughout all of them of varying sizes. I want to find and delete some images but leave the rest.
If I know the size of the images I want to delete, is it possible to do a Find image/Replace with "" based on image dimensions?
Thanks.
macropod
06-23-2022, 12:40 AM
That rather depends on what you mean by 'image dimensions'. If you mean the dimensions in terms of height/width within the document, that's fairly straightforward; if you mean dimensions in terms of pixels, that's rather more difficult - especially if Word's image compression has been used. One wouldn't use Find/Replace, though. For example, the following macro will delete all floating and inline shapes whose width is from 6.0 to 6.5cm (you could, of course, use InchesToPoints instead of CentimetersToPoints):
Sub DelPics()
Application.ScreenUpdating = False
Dim i As Long
With ActiveDocument
For i = .Shapes.Count To 1 Step -1
With .Shapes(i)
If .Width >= CentimetersToPoints(6) Then
If .Width <= CentimetersToPoints(6.5) Then .Delete
End If
End With
Next
For i = .InlineShapes.Count To 1 Step -1
With .InlineShapes(i)
If .Width >= CentimetersToPoints(6) Then
If .Width <= CentimetersToPoints(6.5) Then .Delete
End If
End With
Next
End With
Application.ScreenUpdating = True
End Sub
Helen269
06-23-2022, 06:50 AM
Thank you, that worked! :-)
I did find that putting in the exact dimensions of the graphic didn't work so I made your macro into a sub that took the exact width and set up two variables, one with exact width -.1, the other with exact width +.1. So now I can have a series of calls which pass in the exact widths.
I might adjust it later to work on exact numbers instead of <= and >, but I'm happy for it to just work.
Thank you again! :-)
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.