Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-11-2019, 10:07 AM
Ramses505 Ramses505 is offline Loop through Footnote Reference Marks Windows 7 64bit Loop through Footnote Reference Marks Office 2010
Novice
Loop through Footnote Reference Marks
 
Join Date: May 2019
Posts: 1
Ramses505 is on a distinguished road
Default Loop through Footnote Reference Marks

I have some code that loops through the actual Footnotes that looks like this;


Code:
Sub Test_Format_Footnote()
Dim f As Footnote

For Each f In ActiveDocument.Footnotes
  With f.Range.Characters(1)
    If .Text = vbTab Or .Text = " " Then 'Use any other sensible detection logic here
      .Text = vbTab
    Else
      .InsertBefore "Look Here !"
    End If
  End With
Next
End Sub

How do I loop through the Footnote Reference Marks; the numbers in the text linking to the actual footnote ?


I would like to change the format of them on several ways - I would also like to know how to just loop through them for future reference.


Thanks
Reply With Quote
  #2  
Old 05-11-2019, 04:11 PM
macropod's Avatar
macropod macropod is offline Loop through Footnote Reference Marks Windows 7 64bit Loop through Footnote Reference Marks Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

If you want to change the format of the footnote reference, modify the Footnote Reference Style. That way, you don't need any code to loop through them.

That said, if you have some other reason for looping through them, you might use code like:
Code:
Dim FtNt As Footnote
For Each FtNt In ActiveDocument.Footnotes
  With FtNt.Reference
    'Do stuff
  End With
Next
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 09-19-2023, 07:40 AM
RobiNew RobiNew is offline Loop through Footnote Reference Marks Windows 10 Loop through Footnote Reference Marks Office 2016
Competent Performer
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Question

This code works perfectly for reference marks in the main document, but leaves all reference marks untouched in the footnote section. Can anyone help? Thanks a lot!

Code:
Sub FootnoteMark()
'Format Reference Mark in Main Document and Footnote Section
Dim oStory As Range
Dim FtNt As Footnote
For Each oStory In ActiveDocument.StoryRanges
For Each FtNt In ActiveDocument.Footnotes
      With FtNt.Reference.Font
        .Superscript = True
        .Position = 0
      End With
Next
Next oStory
Set oStory = Nothing
End Sub

Last edited by RobiNew; 09-19-2023 at 07:48 AM. Reason: formatting
Reply With Quote
  #4  
Old 09-19-2023, 03:55 PM
Guessed's Avatar
Guessed Guessed is offline Loop through Footnote Reference Marks Windows 10 Loop through Footnote Reference Marks Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
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

Your code is flawed, it repeats the inner loop on exactly the same thing multiple times. The Footnote References only exist in the Main Story so there is no point in looping through every story range.

You can't actually put footnote references in text boxes, headers, footers or footnote areas because Word doesn't allow it (although you can paste one in and it resets to 1) - so looping through the various ranges to find footnotes serves no purpose (and in fact errors in the below code).

Looking at the code issue, when you want to run a loop across each StoryRange you need to refer to that story range instead of the parent document (see the bold word in this code and compare with your code)
Code:
Sub FootnoteMark()
  Dim oStory As Range, FtNt As Footnote
  For Each oStory In ActiveDocument.StoryRanges
    For Each FtNt In oStory.Footnotes
       'do stuff
    Next
  Next oStory
End Sub
However, this inner loop will fail because Footnotes don't go into different story ranges - just the main body of the document. This means there is no point repeating the inner loop the same number of times as there are story ranges.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia

Last edited by Guessed; 09-19-2023 at 08:10 PM. Reason: added more info
Reply With Quote
  #5  
Old 09-20-2023, 12:24 AM
RobiNew RobiNew is offline Loop through Footnote Reference Marks Windows 10 Loop through Footnote Reference Marks Office 2016
Competent Performer
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Smile

Thanks a lot for your clear explanation of all the aspects of the problem.
The code below shows how I managed to format the marks in the footnote section. Can it be improved? Many thanks!


Code:
Sub FootnoteMark()
'Format Reference Mark in Footnote Section
ActiveWindow.View.SplitSpecial = wdPaneFootnotes
Selection.HomeKey Unit:=wdStory
With Selection.Find
    .Text = "^f"
    End With
Selection.Find.Execute
While Selection.Find.Found = True
With Selection.Font
    .Superscript = True
    .Position = 0
    .Wrap = wdFindStop
End With
Selection.Find.Execute
Wend
ActiveWindow.ActivePane.Close
Selection.HomeKey
End Sub
Reply With Quote
  #6  
Old 09-20-2023, 09:47 PM
Guessed's Avatar
Guessed Guessed is offline Loop through Footnote Reference Marks Windows 10 Loop through Footnote Reference Marks Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
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

If you want to only address the footnote number in the footnote itself you can do it with this code. I recommend you apply the same character style that was applied to the footnote reference in the body of the document.
Code:
Sub FootnoteMark2()
  Dim aFN As Footnote
  For Each aFN In ActiveDocument.Footnotes
'    With aFN.Range.Paragraphs(1).Range.Words(1).Font  'enable this for direct formatting
'      .Superscript = True
'      .Position = 0
'    End With
    aFN.Range.Paragraphs(1).Range.Words(1).Style = "Footnote Reference"  'preferred method is to use a style
  Next aFN
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #7  
Old 09-21-2023, 12:10 AM
RobiNew RobiNew is offline Loop through Footnote Reference Marks Windows 10 Loop through Footnote Reference Marks Office 2016
Competent Performer
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

Many thanks Guessed! That was a real improvement.
I wonder if you could have a look at my question here:
https://www.msofficeforums.com/word-...tml#post177026
Thanks a lot, anyway!
Reply With Quote
Reply

Tags
ref mark ftnt sec



Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop through Footnote Reference Marks Removing line break and indentation between footnote number and footnote text in Word jaanross Word 5 02-06-2020 12:04 AM
Loop through Footnote Reference Marks Footnote reference numbers precede by superscript '(' and follow w/ superscript ')' Swarup Word 4 07-18-2019 05:51 PM
Loop through Footnote Reference Marks How do I fix this unknown problem? Right-angle marks in corners - crop marks Quillo1234 Word 2 07-20-2016 02:24 AM
Loop through Footnote Reference Marks How to keep the footnote(endnote) reference numbers when pasting text between two documents? gn4619 Word 4 10-22-2015 08:01 AM
Get footnote reference GLENCOE Word VBA 1 04-07-2015 04:08 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:05 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft