Macros and Footnotes

L

Lofty Becker

I¹ve got a problem that's ideal for a macro but I'm not sure it can be
done.

I have a large number of fairly long documents with autonumbered
footnotes. (They're Supreme Court opinions, if anyone is curious.)

I want to convert the autonumbered footnotes to fixed-number footnotes,
so that I can edit the opinions for distribution to my class (they
complain if I make them read the full opinions), but not have the
footnotes renumber.

Procedurally, it's easy enough to see how to do this IF Visual Basic has
the needed command. But I'm not sure it does and I'm having trouble
figuring the answer out from the documentation.

WHILE (not EOF)
Find Next Footnote
Convert to fixed number (use a counter if needed)
(Bump counter, if used)
Next
END WHILE

Can anyone give me any pointers?

-Lofty
 
J

John McGhie

Hi Lofty:

There's two ways to do this. You can do it in one line with
ActiveDocument.ConvertNumbersToText

Here's the macro I use...

Sub ConvertNumbers()
' Converts all numbers to text
Dim doIt As Integer

doIt = MsgBox("This macro converts all automatic numbers in the document to
text. This is a one-time operation. Are you sure?", vbOKCancel)

If doIt = 1 Then
ActiveDocument.ConvertNumbersToText
MsgBox "All numbering converted to typed text."
End If

End Sub

This will work well, and is all you need, if you are happy enough to convert
ALL numbering in the document to text.

If you want to do just the footnotes, you need to return the footnotes
collection as a range then apply the method. I haven't had time to test
that, if you need to do that, get back to me.

Cheers


I¹ve got a problem that's ideal for a macro but I'm not sure it can be
done.

I have a large number of fairly long documents with autonumbered
footnotes. (They're Supreme Court opinions, if anyone is curious.)

I want to convert the autonumbered footnotes to fixed-number footnotes,
so that I can edit the opinions for distribution to my class (they
complain if I make them read the full opinions), but not have the
footnotes renumber.

Procedurally, it's easy enough to see how to do this IF Visual Basic has
the needed command. But I'm not sure it does and I'm having trouble
figuring the answer out from the documentation.

WHILE (not EOF)
Find Next Footnote
Convert to fixed number (use a counter if needed)
(Bump counter, if used)
Next
END WHILE

Can anyone give me any pointers?

-Lofty

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Consultant Technical Writer
Sydney, Australia +61 4 1209 1410
 
L

Lofty Becker

John McGhie said:
This will work well, and is all you need, if you are happy enough to convert
ALL numbering in the document to text.

John,

That would be fine, but for me at least that doesn¹t convert the
automatic footnote numbers. (It does convert automatic paragraph
numbers.) As far as I can tell from the documentation, it works on lists
and figure numbers, but not footnote numbers.

I¹m not sure that the Word folks ever imagined that someone would want
to convert automatically numbered footnotes to hard-numbered ones.
Probably if I save the document in RTF format I can figure out a way to
convert the automatic to hard numbers. But I¹d love to do it within the
original document.

Maybe I¹m missing something....

-Lofty
 
D

Daiya Mitchell

Hi Lofty,

MVP Doug Robbins has posted these two macros on WinWord groups, to convert
endnotes to fixed text. You seem comfortable with VBA, so I think you
should be able to edit one of them for your purposes (you may not need to).
Use Word to convert footnotes to endnotes, then run the macros. The two
macros are pretty similar, just slightly tweaked.

I'm not sure that Word can do what you want with footnotes proper, because
it needs that reference number to sort out how to put the footnote text at
the bottom of the page. But presumably endnotes will work?

John may come back with something better, though.

DM

Quoting:
Is there any way to place endnotes in a separate document rather than at
the end of the document?

This is an untested modification of a macro that converted endnotes to
ordinary text at the end of a document:

Dim aendnote As Endnote, Source As Document, Target As Document
Set Source = ActiveDocument
Set Target = Documents.Add
For Each aendnote In Source.Endnotes
Target.Range.InsertAfter vbCr & aendnote.Index & vbTab &
aendnote.Range
aendnote.Reference.InsertBefore "a" & aendnote.Index & "a"
Next aendnote
For Each aendnote In Source.Endnotes
aendnote.Reference.Delete
Next aendnote
Source.Activate
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find.Replacement.Font
.Superscript = True
End With
With Selection.Find
.Text = "(a)([0-9]{1,})(a)"
.Replacement.Text = "\2"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

Here is the original macro

' Macro created 29/09/99 by Doug Robbins to replace endnotes with textnotes
at end of document
' to replace the endnote reference in the body of the document with a
superscript number.
'
Dim aendnote As Endnote
For Each aendnote In ActiveDocument.Endnotes
ActiveDocument.Range.InsertAfter vbCr & aendnote.Index & vbTab &
aendnote.Range
aendnote.Reference.InsertBefore "a" & aendnote.Index & "a"
Next aendnote
For Each aendnote In ActiveDocument.Endnotes
aendnote.Reference.Delete
Next aendnote
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find.Replacement.Font
.Superscript = True
End With
With Selection.Find
.Text = "(a)([0-9]{1,})(a)"
.Replacement.Text = "\2"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
 
J

John McGhie

Sorry Lofty:

It's me who is missing something. Major brain-fade there.

The footnotes are not in the document text, they are in the Footnotes story,
which is a separate section of the document. The footnote reference is the
pointer into a table. As soon as we hammer the footnote reference, we
hammer the footnote itself.

Sorry about that.

Here you go: It's messy, but it works:

Sub ConvertFootnotes()
Dim aFnote As Footnote
Dim numFNotes As Long
Dim aFnoteText As String
Dim aFnoteRef As Range
Dim fNoteNum As Long

numFNotes = ActiveDocument.Footnotes.Count
For fNoteNum = 1 To numFNotes
Set aFnote = ActiveDocument.Footnotes(fNoteNum)
aFnoteText = aFnote.Range.Text
Set aFnoteRef = aFnote.Reference
aFnoteRef.Collapse
aFnote.Delete
ActiveDocument.Footnotes.Add _
Range:=aFnoteRef, _
Text:=aFnoteText, _
Reference:=Str(fNoteNum)
Next ' fNoteNum

End Sub

Note that we can't use a "For... Each..." here because the loop will never
finish, since we add one on each iteration. Similarly, we mustn't have
".Count" inside the loop :)

We need to collapse the range otherwise it will disappear when we delete the
footnote.

I have not found a way to return the actual footnote number from the
existing footnote: it comes back as a non-text object. So I am regenerating
the numbers. Reference is a range, but it's content is not "text".

Hope this helps


John,

That would be fine, but for me at least that doesn¹t convert the
automatic footnote numbers. (It does convert automatic paragraph
numbers.) As far as I can tell from the documentation, it works on lists
and figure numbers, but not footnote numbers.

I¹m not sure that the Word folks ever imagined that someone would want
to convert automatically numbered footnotes to hard-numbered ones.
Probably if I save the document in RTF format I can figure out a way to
convert the automatic to hard numbers. But I¹d love to do it within the
original document.

Maybe I¹m missing something....

-Lofty

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Consultant Technical Writer
Sydney, Australia +61 4 1209 1410
 

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