Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2007

Tip: Looking for answers? Try searching our database.

Select the first shape in a selection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Edward Thrashcort - 20 Mar 2007 14:33 GMT
I just can't work out a method to select the first shape contained within
the current Selection.  

Shapes do not appear to be extractable from the Selection object and each
shape on the Document object is unwilling to tell me its Range so I can test
its position relative to the current Selection.

I'm sure this must be an FAQ?

Eddie
Greg Maxey - 20 Mar 2007 14:41 GMT
Edward,

Will this do:
Sub ScratchMacro()
Selection.Range.ShapeRange(1).Select
End Sub

> I just can't work out a method to select the first shape contained within
> the current Selection.  
[quoted text clipped - 6 lines]
>
> Eddie
Edward Thrashcort - 20 Mar 2007 17:13 GMT
Thanks for that idea.  Unfortunately this does not work if the shape is an
inlineshape.  Clearly I don't understand the object model for graphics, but
I want to select the first picture in a range whether it's floating or
inline with the text.

If it's floating, does it have a range start and a range end relative to the
text that its included-with?

Eddie

> *From:* "Greg Maxey" <gmaxey@gmail.com>
> *Date:* 20 Mar 2007 06:41:22 -0700
[quoted text clipped - 19 lines]
> >
> > Eddie
Greg Maxey - 20 Mar 2007 17:50 GMT
Eddie,

Maybe this will work:

Sub ScratchMacro()
Dim oRng1 As Word.Range
Dim oRng2 As Word.Range
Dim x As Long
Dim y As Long
Set oRng1 = Selection.Range
Set oRng2 = Selection.Range
oRng1.ShapeRange(1).Select
x = Selection.Range.Start
oRng2.InlineShapes(1).Select
y = Selection.Range.Start
If x < y Then
 oRng1.ShapeRange(1).Select
Else
 oRng2.InlineShapes(1).Select
End If
End Sub

> Thanks for that idea.  Unfortunately this does not work if the shape is an
> inlineshape.  Clearly I don't understand the object model for graphics, but
[quoted text clipped - 31 lines]
>
> - Show quoted text -
Edward Thrashcort - 20 Mar 2007 20:33 GMT
Cheers Greg, that does work OK.  I'll have to Count that there are ANY of
each type in the selection before trying to select them - otherwise an error
occurs - but that will work OK.

Your solution is obvious when I see it - I was assuming that InlineShapes
and ShapeRanges would be children of some parent "all graphics" object but
apparently not.

Eddie

> *From:* "Greg Maxey" <gmaxey@gmail.com>
> *Date:* 20 Mar 2007 09:50:45 -0700
[quoted text clipped - 60 lines]
> >
> > - Show quoted text -
Greg Maxey - 20 Mar 2007 20:42 GMT
Eddie,

Yes your right.  I tested on a simple document containing exactly 2
shapes, one inline and one in the drawing layer, and switched them
around.

There may be a more direct approach to this.  I will be the first to
admit that I am not very familiar with working with graphics and
shapes.

Glad I could help.

> Cheers Greg, that does work OK.  I'll have to Count that there are ANY of
> each type in the selection before trying to select them - otherwise an error
[quoted text clipped - 72 lines]
>
> - Show quoted text -
Tony Jollans - 21 Mar 2007 00:52 GMT
A small word of warning here: you need to be clear about what you want to
select. Shapes (not InlineShapes) will be included in the Selection if their
*anchor* is within the selection, wherever they happen to be actually
positioned.

Signature

Enjoy,
Tony

> Eddie,
>
[quoted text clipped - 92 lines]
>>
>> - Show quoted text -
Edward Thrashcort - 21 Mar 2007 13:58 GMT
Yes Tony I've just discovered that a Shape's Range is located at its anchor
point and although it may appear to be included in the current selection, if
it's anchor point is outside, then its not!

If the only thing that is in the selection is a shape, then I've decided to
put out a message recommending that it be converted to inline.

Eddie
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.