bookmark all footnote reference numbers in a document

A

andreas

Dear Experts:
I wonder whether it is possible to achieve the following with the help
of Word VBA

1. bookmark all footnote reference numbers in the main body text
2. bookmark name: the syntax for the bookmarked footnote reference
numbers is to be like ...
fn_1, fn_2, fn_3, ... fn_n ("fn_1" being the bookmark name for the
first footnote; "fn_n" being the bookmark name for the last footnote
in the document)

Help is much appreciated. Thank you very much in advance. Regards,
Andreas
 
L

Lene Fredborg

The following macro should do what you describe:


Sub FootnoteRefs_AddBookmarks()

Dim oRange As Range
Dim n As Long

With ActiveDocument
For n = 1 To .Footnotes.Count
'Define a range that includes the footnote reference
Set oRange = .Range(.Footnotes(n).Reference.Start,
..Footnotes(n).Reference.End)
'Add bookmark
.Bookmarks.Add name:="fn_" & n, Range:=oRange
Next n
End With

'Clean up
Set oRange = Nothing

MsgBox "Finished adding " & n - 1 & " bookmarks around footnote
references."
End Sub

If you run the macro more than once in a document, any existing bookmarks
with names "fn_n" up to the current number of footnotes will be replaced by
new bookmarks.

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
A

andreas

The following macro should do what you describe:

Sub FootnoteRefs_AddBookmarks()

    Dim oRange As Range
    Dim n As Long

    With ActiveDocument
        For n = 1 To .Footnotes.Count
            'Define a range that includes the footnote reference
            Set oRange = .Range(.Footnotes(n).Reference.Start,
.Footnotes(n).Reference.End)
            'Add bookmark
            .Bookmarks.Add name:="fn_" & n, Range:=oRange
        Next n
    End With

    'Clean up
    Set oRange = Nothing

    MsgBox "Finished adding " & n - 1 & " bookmarks around footnote
references."
End Sub

If you run the macro more than once in a document, any existing bookmarks
with names "fn_n" up to the current number of footnotes will be replaced by
new bookmarks.

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmarkwww.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word







- Show quoted text -

Dear Lene,

exactly what I wanted. Thank you so much for your terrific/
professional help. Have a nice day.
Regards, Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top