Consulting

Results 1 to 3 of 3

Thread: Is it possible to find images in document by size then delete them?

  1. #1
    VBAX Regular
    Joined
    Jan 2018
    Posts
    34
    Location

    Is it possible to find images in document by size then delete them?

    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.

  2. #2
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    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
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Regular
    Joined
    Jan 2018
    Posts
    34
    Location
    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! :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •