Selecting textboxes in order the appear in doc 
Author Message
 Selecting textboxes in order the appear in doc

Hi

I've got a doc full of text boxes, but if I itterate through them in turn
(for i=1 to .shapes.count) it goes in the order they were inserted, rather
than the order they appear.  Is there any way to go through the document by
order of appearance?

Thanks in advance

Jon



Mon, 15 Nov 2004 17:53:43 GMT  
 Selecting textboxes in order the appear in doc
A quicker way to iterate the textboxes is to use the
StoryRanges(wdTextFrameStory) collection:

Dim r as range
Set r = ActiveDocument.StoryRanges(wdTextFrameStory)
Do until r is nothing
    ....
    set r = r.nextstoryrange
Loop

But this also returns them in insertion order (it just has the advantage
that it doesn't return anything except text boxes.) The only way I know to
sort them into document order is to fill an array from the Information
property for each textbox with the page number and position, then sort.the
array. I hope someone knows a better way.


Quote:
> Hi

> I've got a doc full of text boxes, but if I itterate through them in turn
> (for i=1 to .shapes.count) it goes in the order they were inserted, rather
> than the order they appear.  Is there any way to go through the document
by
> order of appearance?

> Thanks in advance

> Jon



Mon, 15 Nov 2004 19:26:52 GMT  
 Selecting textboxes in order the appear in doc
Hi Jon,

Quote:
> I've got a doc full of text boxes, but if I itterate through them in turn
> (for i=1 to .shapes.count) it goes in the order they were inserted, rather
> than the order they appear.  Is there any way to go through the document by
> order of appearance?

Actually, it should go through them in the order they're ANCHORED in the
document. I assume you're seeing the behavior with objects that are on the
same page? Move the anchors in the order you want to jump to the text
boxes...

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.mvps.org/word
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)



Mon, 15 Nov 2004 21:42:30 GMT  
 Selecting textboxes in order the appear in doc
Cindy

The anchors are in the correct order, but word still selects the first
created box first.  Am I doing something wrong?

this _should_ take each picture and put it at the start of the document, it
does, but in creation order not anchor order
Sub main()
 Dim pasterange As Range
 Dim s As Shape
 Dim i As InlineShape
 Set pasterange = ActiveDocument.Range(0, 0)
  For Each s In ActiveDocument.Shapes
   If s.TextFrame.HasText Then
    For Each i In s.TextFrame.TextRange.InlineShapes
     i.Range.Copy
     pasterange.Collapse Direction:=wdCollapseEnd
     pasterange.PasteSpecial Placement:=wdInline
    Next i
   End If
  Next s
End Sub



Quote:
> Hi Jon,

> > I've got a doc full of text boxes, but if I itterate through them in
turn
> > (for i=1 to .shapes.count) it goes in the order they were inserted,
rather
> > than the order they appear.  Is there any way to go through the document
by
> > order of appearance?

> Actually, it should go through them in the order they're ANCHORED in the
> document. I assume you're seeing the behavior with objects that are on the
> same page? Move the anchors in the order you want to jump to the text
> boxes...

> Cindy Meister
> INTER-Solutions, Switzerland
> http://homepage.swissonline.ch/cindymeister
> http://www.mvps.org/word
> http://go.compuserve.com/MSOfficeForum

> This reply is posted in the Newsgroup; please post any follow question or
> reply in the newsgroup and not by e-mail :-)



Tue, 16 Nov 2004 17:25:38 GMT  
 Selecting textboxes in order the appear in doc
Hi Jon

Try changing this line

   For Each s In ActiveDocument.Shapes

to this

   For Each s In ActiveDocument.Range.Shapes

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
Word FAQs at http://www.multilinker.com/wordfaq
Please post any follow-up in the newsgroup. I do not reply to Word questions
by email


Quote:
> Cindy

> The anchors are in the correct order, but word still selects the first
> created box first.  Am I doing something wrong?

> this _should_ take each picture and put it at the start of the document,
it
> does, but in creation order not anchor order
> Sub main()
>  Dim pasterange As Range
>  Dim s As Shape
>  Dim i As InlineShape
>  Set pasterange = ActiveDocument.Range(0, 0)
>   For Each s In ActiveDocument.Shapes
>    If s.TextFrame.HasText Then
>     For Each i In s.TextFrame.TextRange.InlineShapes
>      i.Range.Copy
>      pasterange.Collapse Direction:=wdCollapseEnd
>      pasterange.PasteSpecial Placement:=wdInline
>     Next i
>    End If
>   Next s
> End Sub



> > Hi Jon,

> > > I've got a doc full of text boxes, but if I itterate through them in
> turn
> > > (for i=1 to .shapes.count) it goes in the order they were inserted,
> rather
> > > than the order they appear.  Is there any way to go through the
document
> by
> > > order of appearance?

> > Actually, it should go through them in the order they're ANCHORED in the
> > document. I assume you're seeing the behavior with objects that are on
the
> > same page? Move the anchors in the order you want to jump to the text
> > boxes...

> > Cindy Meister
> > INTER-Solutions, Switzerland
> > http://homepage.swissonline.ch/cindymeister
> > http://www.mvps.org/word
> > http://go.compuserve.com/MSOfficeForum

> > This reply is posted in the Newsgroup; please post any follow question
or
> > reply in the newsgroup and not by e-mail :-)



Tue, 16 Nov 2004 17:41:30 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Macro Warning appears - No Module in doc

2. activex doc appearing as binary junk in web browser

3. 2nd Word doc appears after Word template - only in Vista

4. How to make first letter of textbox appear only

5. Can't get cursor to appear in textbox

6. Bindingd Dataset to Textbox appears flawed.

7. Masking a password textbox to appear as all *****

8. An Unwanted Comma appears in TextBox

9. How can I automatically select a picture to appear when I

10. Selected ListItem to appear in StatusBar Panel

11. I want selected item from list box to appear in grid

12. SELECT box not appearing

 

 
Powered by phpBB® Forum Software