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 / November 2004

Tip: Looking for answers? Try searching our database.

For Each doesn't work with Footnotes?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Boutang - 23 Nov 2004 16:13 GMT
For a W95-style help project, I'm trying to print an ordered list of document
footnotes. I've discovered what seems to be a bug in the Footnotes
collection.

Specifically, if you use For Each-Next with .Range.Footnotes, you get all
footnotes in the document instead of all footnotes in the range you've
specified.

Can anyone else confirm, or point out where my code is wrong?

Thanks.

Here's my code, commented where I think the bug is:

For Each ftnTopic In Documents(pstrDoc).Footnotes
 If ftnTopic.Reference.Text = "#" Then  'It's a context ID
   strTitle = ""
   strBrowse = ""
   'Get Topic Title and Browse Sequence

'I think this next line is buggy. For my document,
'.Range.Footnotes.Count=4, yet the For Each construct
'loops through every footnote in the document. This
'wrecks the values put into strTitle & strBrowse

   For Each ftn In _
     ftnTopic.Reference.Paragraphs(1).Range.Footnotes

     If ftn.Reference.Text = "$" Then 'Topic Title
       strTitle = ftn.Range.Text
     End If
     If ftn.Reference.Text = "+" Then 'Browse Sequence
       strBrowse = ftn.Range.Text
     End If
   Next ftn
   
   Documents(pstrDocNew).Range.InsertAfter """" _
     & pstrDoc & """, """ & ftnTopic.Range.Text & """, """ _
     & strTitle & """, """ & strBrowse & """" & vbCrLf
 End If
Next ftnTopic
Doug Robbins - 24 Nov 2004 01:00 GMT
It's not a problem with For Each.  It must be something else with your code.

The following works with both footnotes and endnotes as long as the object
type and references are changed as appropriate.

' Macro created 29/09/99 by Doug Robbins to replace endnotes with textnotes
at end of document

' to replace the endnote reference in the body of the document with a
superscript number.

'

   Dim aendnote As Endnote

   For Each aendnote In ActiveDocument.Endnotes

       ActiveDocument.Range.InsertAfter vbCr & aendnote.Index & vbTab &
aendnote.Range

       aendnote.Reference.InsertBefore "a" & aendnote.Index & "a"

   Next aendnote

   For Each aendnote In ActiveDocument.Endnotes

       aendnote.Reference.Delete

   Next aendnote

   Selection.Find.ClearFormatting

   Selection.Find.Replacement.ClearFormatting

   With Selection.Find.Replacement.Font

       .Superscript = True

   End With

   With Selection.Find

       .Text = "(a)([0-9]{1,})(a)"

       .Replacement.Text = "\2"

       .Forward = True

       .Wrap = wdFindContinue

       .Format = True

       .MatchWildcards = True

   End With

   Selection.Find.Execute Replace:=wdReplaceAll
Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> For a W95-style help project, I'm trying to print an ordered list of
> document
[quoted text clipped - 38 lines]
>  End If
> Next ftnTopic
Boutang - 24 Nov 2004 14:43 GMT
Thanks for your post, Doug. Actually, the problem IS with For Each, or at
least with the way For Each interacts with the Footnotes collection when that
collection is referenced via the following call:

For Each ftnTopic In ActiveDocument.Footnotes
 For Each ftn In ftnTopic.Reference.Paragraphs(1).Range.Footnotes
   'do something here
 Next ftn
Next ftnTopic

(In other words, look at an existing footnote, find the paragraph that it's
in, then take THAT paragraph's Footnotes collection.)

I'm pretty sure the problem is with For Each because Access 2.0-style coding
works just fine in the "inner" Footnotes loop, as follows:

For Each ftnTopic In ActiveDocument.Footnotes
 For intCounter = 1 To ftnTopic.Reference.Paragraphs(1).Range.Footnotes.Count
   Set ftn = ftnTopic.Reference.Paragraphs(1).Range.Footnotes(intCounter)
   'put code here to work with invidual footnotes
 Next intCounter
Next ftnTopic

I think Word is having problems dealing with two Footnotes collections at
once: one for the current document, and then one for a particular paragraph.
 
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.