Results 1 to 5 of 5

Thread: applying hyperlink styles in footnotes and endnotes

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    You can't use autoformat in the notes themselves, but you can copy the notes to a document, format them there then copy them back again. The following should work

    Option Explicit
    
    Sub LinkNotes()
        Dim oDoc As Document
        Dim oTemp As Document
        Dim oNote As Range
        Dim oFN As Footnote
        Dim oEN As EndNote
        Dim oRng As Range
        Set oDoc = ActiveDocument
        oDoc.Save
        Set oTemp = Documents.Add(Template:=oDoc.FullName, Visible:=False)
        For Each oFN In oDoc.Footnotes
            Set oNote = oFN.Range
            Set oRng = oTemp.Range
            oRng.FormattedText = oNote.FormattedText
            oRng.Style = "Footnote Text"
            Options.AutoFormatReplaceHyperlinks = True
            oRng.AutoFormat
            oRng.End = oRng.End - 1
            oNote.FormattedText = oRng.FormattedText
        Next oFN
        For Each oEN In oDoc.Endnotes
            Set oNote = oEN.Range
            Set oRng = oTemp.Range
            oRng.FormattedText = oNote.FormattedText
            oRng.Style = "Footnote Text"
            Options.AutoFormatReplaceHyperlinks = True
            oRng.AutoFormat
            oRng.End = oRng.End - 1
            oNote.FormattedText = oRng.FormattedText
        Next oEN
        oTemp.Close savechanges:=wdDoNotSaveChanges
        lbl_Exit:
        Set oEN = Nothing
        Set oFN = Nothing
        Set oDoc = Nothing
        Set oTemp = Nothing
        Set oRng = Nothing
        Set oNote = Nothing
        Exit Sub
    End Sub
    With a few small modifications to that code you should also be able to use it with http://www.gmayor.com/document_batch_processes.htm as a custom process to enable you to batch process your documents.

    Option Explicit
    
    Function LinkNotes(oDoc As Document) As Boolean
        Dim oTemp As Document
        Dim oNote As Range
        Dim oFN As Footnote
        Dim oEN As EndNote
        Dim oRng As Range
        On Error GoTo err_Handler
        Set oTemp = Documents.Add(Template:=oDoc.FullName, Visible:=False)
        For Each oFN In oDoc.Footnotes
            Set oNote = oFN.Range
            Set oRng = oTemp.Range
            oRng.FormattedText = oNote.FormattedText
            oRng.Style = "Footnote Text"
            Options.AutoFormatReplaceHyperlinks = True
            oRng.AutoFormat
            oRng.End = oRng.End - 1
            oNote.FormattedText = oRng.FormattedText
        Next oFN
        For Each oEN In oDoc.Endnotes
            Set oNote = oEN.Range
            Set oRng = oTemp.Range
            oRng.FormattedText = oNote.FormattedText
            oRng.Style = "Footnote Text"
            Options.AutoFormatReplaceHyperlinks = True
            oRng.AutoFormat
            oRng.End = oRng.End - 1
            oNote.FormattedText = oRng.FormattedText
        Next oEN
        oTemp.Close savechanges:=wdDoNotSaveChanges
        LinkNotes = True
        lbl_Exit:
        Set oEN = Nothing
        Set oFN = Nothing
        Set oDoc = Nothing
        Set oTemp = Nothing
        Set oRng = Nothing
        Set oNote = Nothing
        Exit Function
    err_Handler:
        LinkNotes = False
        Resume lbl_Exit
    End Function
    Last edited by Aussiebear; 03-11-2025 at 12:10 AM.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •