#1
|
|||
|
|||
How to delete images from entire Word document
I have a very long (9000 page) .rtf Word document. It was created via OCR from 9000 pages of hardcopy. Occasionally the text includes images (as per the attached image). I realise there is the option of replacing all graphics with nothing, and that should delete all the images. (As in find ^g replace [leave blank]). Nonetheless when I do this it says there were zero replacements made. This is driving me crazy, as clearly there are graphics inside the document. Could the images I see be something other than graphics? How can I delete them all? |
#2
|
|||
|
|||
Hi, maybe this will help you... How to select multiple photos in Word and why is it blank when selecting multiple objects-Lionsure
|
#3
|
||||
|
||||
Documents are made up of a variety of story ranges or 'layers'. Inline graphics are in the text layer and will be accessed with ^g. Images that have a wrap option set are in the graphics layer and thus will not. You need to change the wrap to in-line in order to remove them by this method.
An alternative is to use a macro. The following should remove floating graphics Code:
Sub Macro1() Dim oShape As Shape Dim i As Integer For i = ActiveDocument.Shapes.Count To 1 Step -1 Set oShape = ActiveDocument.Shapes(i) If oShape.Type = msoPicture Then oShape.Delete Next i Set oShape = nothing End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#4
|
|||
|
|||
Thanks so much for the response. I haven't had a lot of experience with running Macros.
I thought I had done everything right, but when I run the Macro you gave me I get a message "Microsoft Visual Basic for Applications. Compile error: Expected End Sub" What have I done wrong? |
#5
|
||||
|
||||
You probably missed the last line of code when you pasted it into VBA
It should end with a line that says End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#6
|
|||
|
|||
Do layered images exist in Word 2000? Where can I find more info about them?
|
#7
|
|||
|
|||
Quote:
Going to the View tab in Word. Clicking on Macros -> View Macros -> Create Then I get a screen that says: Sub Macro1() ' ' Macro1 Macro ' ' End Sub I am deleting all of that and pasting in: Sub Macro1() Dim oShape As Shape Dim i As Integer For i = ActiveDocument.Shapes.Count To 1 Step -1 Set oShape = ActiveDocument.Shapes(i) If oShape.Type = msoPicture Then oShape.Delete Next i Set oShape = nothing End Sub I change the name to ImageRemover and get the below code: Sub Macro1() Dim oShape As Shape Dim i As Integer For i = ActiveDocument.Shapes.Count To 1 Step -1 Set oShape = ActiveDocument.Shapes(i) If oShape.Type = msoPicture Then oShape.Delete Next i Set oShape = Nothing End Sub Sub ImageRemover() End Sub I then hit F5 -> Run Lo and behold, the images still remain in the document. I have already removed a fair number of images, by using ^g and replacing it with nothing. There are still heaps of other images though in my 9000 page document that remain. |
#8
|
||||
|
||||
ImageRemover has no code in it so I'm not surprised nothing happens with that macro.
The other macro is testing each floating shape to see what it's type is and only deleting them if they are an msoPicture. Apparently the shapes you want to get rid of are not msoPicture types so maybe you don't want to restrict the macro to only msoPicture. You could ask the macro to tell you what types of shapes are in the document by changing this line Code:
If oShape.Type = msoPicture Then oShape.Delete Code:
If oShape.Type = msoPicture Then oShape.Delete Else Debug.Print oShape.Type End If
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#9
|
|||
|
|||
Thanks again for all your assistance. I couldn't seem to sort it out with that code either, but I decided to copy all the text and paste it into a new document as text.
That seems to have done the job for now. It may screw with the formatting a bit, though so far any changes have been easy to manually fix. |
Tags |
deleting, graphics, photos |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Create Word macro to delete text throughout the entire document | JTell | Word VBA | 8 | 07-06-2022 12:19 PM |
Delete entire paragraph after key word | jeffreybrown | Word | 2 | 07-27-2018 02:29 PM |
Single step Word Styles from Source Document through entire Destination document? | xbliss | Word | 6 | 08-27-2016 09:36 PM |
MS Word auto formats entire document with EVERY change | rooter | Word | 2 | 02-22-2015 10:05 AM |
New here: How do i delete an entire notebook? | DixieSister | OneNote | 2 | 02-20-2015 12:45 PM |