This is just an educated guess...
When you call SrcRg.Find.Execute the first time, and it finds a Heading 2, the
location of SrcRg is changed to the location of the Heading 2. Every other time
through the outer For loop, the Find is executed on that SrcRg location -- so it
finds only the Heading 2 that it found the first time, which isn't on the same
page with any of the other frames. Therefore, none of the other pages print.
To fix this in a simple fashion, you could move the "Set SrcRg" line to be
_after_ the "For Each frm" line. Then for each frame the heading search will
start again at the beginning of the document and search to the correct heading.
Actually, this is a rather inefficient way to go about it. Presumably each frame
occurs somewhere in the document after its predecessor, so each frame's search
should start just after the end of the preceding Heading 2. That way the code
doesn't have to test every Heading 2 from the beginning of the document on every
iteration of the For Each loop.
To do this, leave the "Set SrcRg" line where it is. Instead, between the "End
With" and the "Next" add this line:
Set SrcRg = ActiveDocument.Range(Start:=SrcRg.End + 1, _
End:=ActiveDocument.Range.End)
(Caveat: Not tested, may need some tweaking!)
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
>So what I'm trying to do is loop through all the frames in my
>document, and see if they're on the same page as text with the style
[quoted text clipped - 34 lines]
>
>Can anyone smart tell me what's going on here?
osirun@gmail.com - 14 Mar 2008 16:50 GMT
Thanks Jay! I ran into problems with the second, more efficient
solution, but the first idea worked like a charm. I'm just relieved
to get something that works at all... and starting to understand how
VBA works a little better :)