Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-30-2020, 08:49 AM
alex100 alex100 is offline Remove image placeholders Windows 7 64bit Remove image placeholders Office 2016
Advanced Beginner
Remove image placeholders
 
Join Date: May 2020
Posts: 43
alex100 is on a distinguished road
Default Remove image placeholders

In case Word is not able to retrieve an image when you paste an article from the web (because of a bad connection, for example), it will instead insert a placeholder on that location.

I am trying to remove these, and so far I have the code below, but it's far from working as it should...

Code:
For Each oShape In ActiveDocument.Shapes
    If oShape.AutoShapeType = msoShapeRectangle Then
        oShape.Delete
    End If
Next
It does remove some of the placeholders, but not all of them, as some will be left behind.



Then, how can I execute the code for the current selection only, instead of the entire document?

Thank you!

Alex
Reply With Quote
  #2  
Old 06-30-2020, 06:32 PM
Guessed's Avatar
Guessed Guessed is offline Remove image placeholders Windows 10 Remove image placeholders Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,658
Guessed is a glorious beacon of lightGuessed is a glorious beacon of lightGuessed is a glorious beacon of lightGuessed is a glorious beacon of lightGuessed is a glorious beacon of light
Default

On your first question, loops that delete items should always start from the back of the line rather than starting from the front. Imagine you have a queue of items where you remove item 3 and step to (the now) item 4. The end effect of this is that your loop skips any item immediately after any item that is deleted.

To avoid this procedural issue, you start from the back
Code:
For i = ActiveDocument.Shapes.Count to 1 Step -1
  If ActiveDocument.Shapes(i).AutoShapeType = msoShapeRectangle then ActiveDocument.Shapes(i).Delete
Next i
When you ask about current selection, there are two possible types of selections relevant to Shapes - because they are 'floating' objects that don't reside in the same layer as the text.

If you have selected the shapes themselves, you can use
Selection.ShapeRange.Count

If you have selected the text where some shapes are anchored, this is much more difficult and you would need to loop through all the ActiveDocument.Shapes and test whether their anchor is in the selected text.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 06-30-2020, 11:42 PM
alex100 alex100 is offline Remove image placeholders Windows 7 64bit Remove image placeholders Office 2016
Advanced Beginner
Remove image placeholders
 
Join Date: May 2020
Posts: 43
alex100 is on a distinguished road
Default

Indeed, looping from the back made all the difference! The code does now replace all the image placeholders.

Thank you!

Alex
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Placeholders Marina Word 9 12-17-2019 03:28 PM
How do I animate so: small image ==> large image ==> text over overlaid ==> back to next image ship69 PowerPoint 0 09-27-2019 12:55 PM
Remove image paths from Word to PDF convertion gwk1975 Word 0 07-30-2014 05:02 AM
Description of Uses/Differences in Placeholders CathClaud Mail Merge 6 06-23-2014 06:31 PM
Remove image placeholders Removing Placeholders When printing DeadBatteries Word 3 08-23-2012 01:08 AM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 03:46 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft