#1
|
|||
|
|||
Delete identical images
Hi all,
I'm trying to automate the process of deleting old (dated) icons and images from a word document. The same images are repeated throughout the document. I've written this macro to delete images 'identical' to the selected. As the images do not seem to have names, I've been finding images of the same dimensions (imperfect I know). Is there a better way to do this or a way to find a unique identifier for identical shapes (even if resized)? A number of the icons have been slightly resized so I have to run this macro multiple times. Heres what I've got: Code:
Sub DeleteSelectedPicture() Dim Shp As Shape, iShp As InlineShape Dim DC As Integer, SHeight As Variant, SWidth As Variant DC = 0 If Selection.InlineShapes.Count = 1 Then SHeight = Selection.InlineShapes(1).Height SWidth = Selection.InlineShapes(1).Width End If If Selection.ShapeRange.Count = 1 Then SHeight = Selection.ShapeRange(1).Height SWidth = Selection.ShapeRange(1).Width End If With ActiveDocument For Each iShp In .InlineShapes If iShp.Height = SHeight And iShp.Width = SWidth Then iShp.Delete DC = DC + 1 End If Next For Each Shp In .Shapes If Shp.Height = SHeight And Shp.Width = SWidth Then Shp.Delete DC = DC + 1 End If Next MsgBox DC & " pictures deleted." End With End Sub |
#2
|
||||
|
||||
I think what you are asking for sounds like it SHOULD be easy but it is NOT.
Unique identifier implies there is no more than one of them so although every graphic has a unique id, it is not going to be useful to search for other instances of that unique id because if there was another one it wouldn't actually be unique. Size is not a valid thing to work with either since icons should be built to a specific 'static' size. Another way to identify 'duplicates' is to use the underlying file properties. If you copy and paste a graphic which is already in the document, it won't add a second copy of the graphic in the word/media folder of the zipped docx file. This implies that you could parse the xml contents of the document.xml file but this looks exceptionally tricky and more involved than I have time for. It is also likely to be incomplete because if you insert a copy of the same graphic into the doc, you do get a new instance in the media folder. Also any picture corrections on a copy will give you a new instance in the media folder. The way I would 'identify' a family of duplicates is to use the AlternativeText or Title property for each graphic. Copies would have the same name and therefore be quick to find. The drawback is that this requires you to have already labelled this property for every graphic.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Identical computers | MeCasa | Office | 0 | 09-23-2019 03:43 PM |
how to delete multiple images at the same time in all slides. | yeshwanthkota111 | PowerPoint | 2 | 09-10-2015 04:04 AM |
how to show identical data once only? | heidiau | Mail Merge | 1 | 09-29-2013 07:44 PM |
flag identical words? | 21rouge | Word | 1 | 09-21-2013 08:42 AM |
Delete all shapes but not the images - Possible? | AlmostFriday | Word VBA | 10 | 12-14-2011 12:04 AM |