Macro: Remove all the images in a Word document Thread poster: Hans Lenting
|
Sometimes you want to remove all images (e.g. to reduce the file size). I found this macro: https://www.msofficeforums.com/word-vba/44918-remove-all-images-document-including-new-lines.html Works on Mac too. Public Sub ReplaceAllGraphicsWithNothing() Dim rngStory As Word... See more Sometimes you want to remove all images (e.g. to reduce the file size). I found this macro: https://www.msofficeforums.com/word-vba/44918-remove-all-images-document-including-new-lines.html Works on Mac too. Public Sub ReplaceAllGraphicsWithNothing() Dim rngStory As Word.Range Dim lngJunk As Long Dim lngIndex As Long 'Fix the skipped blank Header/Footer problem lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType 'Iterate through all story types in the current document For Each rngStory In ActiveDocument.StoryRanges 'Iterate through all linked stories Do SrcAndRplInStory rngStory, "^g^p", "" SrcAndRplInStory rngStory, "^g^l", "" SrcAndRplInStory rngStory, "^g", "" For lngIndex = rngStory.ShapeRange.Count To 1 Step -1 rngStory.ShapeRange.Item(lngIndex).Delete Next lngIndex 'Get next linked story (if any) Set rngStory = rngStory.NextStoryRange Loop Until rngStory Is Nothing Next lbl_Exit: Exit Sub End Sub Public Sub SrcAndRplInStory(ByVal rngStory As Word.Range, _ ByVal strSearch As String, _ ByVal strReplace As String) With rngStory.Find .ClearFormatting .Replacement.ClearFormatting .Text = strSearch .Replacement.Text = strReplace .Execute Replace:=wdReplaceAll End With lbl_Exit: Exit Sub End Sub
[Edited at 2023-01-06 08:39 GMT] ▲ Collapse | | | Dalia Nour Egypt Local time: 03:14 Member (2018) English to Arabic + ...
Thanks for sharing, Hans! | | | Stepan Konev Russian Federation Local time: 03:14 English to Russian
You can also replace ^g with blank field to remove images. | | | Hans Lenting Netherlands Member (2006) German to Dutch TOPIC STARTER
Stepan Konev wrote: You can also replace ^g with blank field to remove images. The documents were old .doc files. If I'm not mistaken, Microsoft has changed the way graphics are embedded in layers since then. Anyway, this didn't work (in Page View): The macro does work. And I like to combine tiny tasks, which is only possible with macros: Sub Test() ' ' This macro is assigned to Ctrl+Alt+T ' Do not delete this macro! ' SaveActiveDocumentAsDocx ReplaceAllGraphicsWithNothing ActiveDocument.save ActiveDocument.Close End Sub | |
|
|
Stepan Konev Russian Federation Local time: 03:14 English to Russian Macro uses ^g too | Jan 7, 2023 |
Hans Lenting wrote: The macro does work. Weirdly it works for me... Probably it somehow relates to the format of images. However, as far as I can see now from the code, the macro uses exactly the same ^g. Right? Update: Ah, ok, I have read the entire discussion. I see now. The macro also removes all floating images. When I prepare a file for translation, I make all images inline. That's is why simple replacement of ^g with a blank value works for me. However, if you have both inline and floating images, then the macro is a better choice indeed.
[Edited at 2023-01-07 06:19 GMT] | | | Hans Lenting Netherlands Member (2006) German to Dutch TOPIC STARTER
Stepan Konev wrote: Hans Lenting wrote: The macro does work. Weirdly it works for me... Probably it somehow related to the format of images. However, as far as I can see now from the code, the macro uses exactly the same ^g. Right? Yes. But obviously, strange things DO happen. | | | To report site rules violations or get help, contact a site moderator: You can also contact site staff by submitting a support request » Macro: Remove all the images in a Word document Trados Business Manager Lite | Create customer quotes and invoices from within Trados Studio
Trados Business Manager Lite helps to simplify and speed up some of the daily tasks, such as invoicing and reporting, associated with running your freelance translation business.
More info » |
| Trados Studio 2022 Freelance | The leading translation software used by over 270,000 translators.
Designed with your feedback in mind, Trados Studio 2022 delivers an unrivalled, powerful desktop
and cloud solution, empowering you to work in the most efficient and cost-effective way.
More info » |
|
| | | | X Sign in to your ProZ.com account... | | | | | |