Consulting

Results 1 to 7 of 7

Thread: Converting glossary to footnotes

  1. #1
    VBAX Newbie
    Joined
    Jun 2021
    Posts
    4
    Location

    Converting glossary to footnotes

    Hi

    I've a .doc with a table of glossary at the end of the document. The first row of table contains the terms (a word or an expression) , the second one contains the definitions. I would like to convert this glossary to classic footnotes. Of course I can do it manually (search for the first appearance of the term, insert a footnote, copy the definition into it), but the glossary has more than 600 terms, so it would be a really time consuming and boring work. Are there any way to solve it using VBA?

    Thanks for any help.

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    You would probably do better to retain the Glossary and hyperlink the terms in the document to it.

    Nevertheless, if you're determined to go down the path you describe, what do you want to happen if the same term appears multiple times in the document:
    a) have multiple footnotes with identical content to maintain?; or
    b) insert the content in the first footnote, then cross-reference the other instances of the term to that footnote?
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Newbie
    Joined
    Jun 2021
    Posts
    4
    Location
    I would like to insert the content only in the first footnote without any cross-reference to the other instances. It is not a scientific work but a novel from the 19th century using a rather bolted language. I need a well formed Word document as source to convert it a well formed epub showing in page footnotes.

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    A Word macro to do as you describe is:
    Sub Demo()
    Application.ScreenUpdating = False
    Dim Tbl As Table, StrFnd As String, Rng As Range, FtNt As Footnote, r As Long
    With ActiveDocument
      Set Tbl = .Tables(.Tables.Count)
      Tbl.Range.Style = wdStyleFootnoteText
      For r = 1 To Tbl.Rows.Count
        Set Rng = Tbl.Cell(r, 2).Range
        Rng.End = Rng.End - 1
        StrFnd = Trim(Split(Tbl.Cell(r, 1).Range.Text, vbCr)(0))
        With .Range
          With .Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Format = False
            .Text = StrFnd
            .Wrap = wdFindStop
            .MatchWholeWord = True
            .MatchWildcards = False
            .MatchCase = True
            .Execute
          End With
          .Collapse wdCollapseEnd
          Set FtNt = .Footnotes.Add(Range:=.Duplicate)
          With FtNt.Range
            .FormattedText = Rng.FormattedText
            .CollapsewdCollapseStart
            .Text = StrFnd & ": "
            .Style = wdStyleStrong
          End With
        End With
      Next
      Tbl.Delete
    End With
    Application.ScreenUpdating = True
    End Sub
    Last edited by macropod; 06-10-2021 at 03:27 PM.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    VBAX Newbie
    Joined
    Jun 2021
    Posts
    4
    Location
    Thank you very much! After some changes in the code (.MatchWholeWord = False and .MatchCase = False) your macro generated 540 footnotes of the whole 600. Sometimes the root of Hungarian words alter after conjugation, so I guess the rest would be tricky to solve.
    Just another question if I'm not importunate. Is it possible to insert not only the definition, but both the term AND definition (something like: "term - definition") in footnotes?

  6. #6
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Quote Originally Posted by gkoscso View Post
    After some changes in the code (.MatchWholeWord = False and .MatchCase = False) your macro generated 540 footnotes of the whole 600. Sometimes the root of Hungarian words alter after conjugation, so I guess the rest would be tricky to solve
    Setting .MatchWholeWord = False is liable to end up with footnote references being inserted within a word rather than after it. You might do better to add .MatchAllWordForms = True.
    Quote Originally Posted by gkoscso View Post
    Is it possible to insert not only the definition, but both the term AND definition (something like: "term - definition") in footnotes?
    See revised code.
    Last edited by macropod; 06-10-2021 at 05:24 PM.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  7. #7
    VBAX Newbie
    Joined
    Jun 2021
    Posts
    4
    Location
    Quote Originally Posted by macropod View Post
    Setting .MatchWholeWord = False is liable to end up with footnote references being inserted within a word rather than after it. You might do better to add .MatchAllWordForms = True.
    I don't know why, but MatchAllWordForms doesn't work for me (maybe Hungarian language again). Anyway, I can easily fix those inserted footnotes with a simple Search&Replace using regular expressions in the final epub, so it is not a big problem.

    Thank you so much again, your macro spared me a LOT of time.

Posting Permissions

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