Macro: Remove all the images in a Word document Автор темы: Hans Lenting
| Hans Lenting Нидерланды Член ProZ.com c 2006 немецкий => голландский
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 Египет Local time: 10:33 Член ProZ.com c 2018 английский => арабский + ...
Thanks for sharing, Hans! | | |
You can also replace ^g with blank field to remove images. | | | Hans Lenting Нидерланды Член ProZ.com c 2006 немецкий => голландский Автор темы
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 | |
|
|
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 Нидерланды Член ProZ.com c 2006 немецкий => голландский Автор темы
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 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 » |
| Protemos translation business management system | Create your account in minutes, and start working! 3-month trial for agencies, and free for freelancers!
The system lets you keep client/vendor database, with contacts and rates, manage projects and assign jobs to vendors, issue invoices, track payments, store and manage project files, generate business reports on turnover profit per client/manager etc.
More info » |
|
| | | | X Sign in to your ProZ.com account... | | | | | |