PDA

View Full Version : [SOLVED:] Converting glossary to footnotes



gkoscso
06-09-2021, 06:33 AM
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.

macropod
06-09-2021, 03:45 PM
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?

gkoscso
06-10-2021, 02:10 AM
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.

macropod
06-10-2021, 02:59 AM
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

gkoscso
06-10-2021, 08:36 AM
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?

macropod
06-10-2021, 03:26 PM
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.

Is it possible to insert not only the definition, but both the term AND definition (something like: "term - definition") in footnotes?See revised code.

gkoscso
06-11-2021, 08:22 AM
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.