View Single Post
 
Old 06-30-2020, 06:32 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
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