M
mccaskey
I want a (well-behaved) field whose result can be a reference to a
footnote.
I found, with a little sidestep, I can do it with the (barely
documented and poorly behaved) { ADDIN } field as follows:
Sub insertNote()
' create the field
Set fField = ActiveDocument.Fields.Add(Selection.Range,
wdFieldQuote, "text")
fField.Code.Text = " ADDIN "
fField.Result.Text = ""
' add the footnote
Set note = ActiveDocument.Footnotes.Add(Range:=fField.Result)
note.Range.Text = "Hello"
End Sub
Run this and you have a field whose result is a reference to a
footnote whose content is "Hello". Cool.
But alas, all is not well. Manually add another footnote to the
document. Put "Goodbye" into the footnote.
Now run this routine:
Sub scanNote()
MsgBox ActiveDocument.Fields(1).Result.Footnotes.Count
For Each myfootnote In ActiveDocument.Fields(1).Result.Footnotes
MsgBox myfootnote.Range.Text
Next myfootnote
End Sub
The first MsgBox says that there is one footnote in the result of the
field. That's right.
But the loop then iterates through all footnotes in the whole
document. That's wrong. This seems a bug in ADDIN, but since that
field is a secret of sorts anyway (and maybe I wasn't supposed to be
able to put a note reference in it in the first place), I guess I
can't complain.
My problem is that given the field, I need to go look at the content
of the footnote, but I can't.
Any suggestions appreciated. (I'm using Word 2003 but I need this to
work with newer versions also.)
footnote.
I found, with a little sidestep, I can do it with the (barely
documented and poorly behaved) { ADDIN } field as follows:
Sub insertNote()
' create the field
Set fField = ActiveDocument.Fields.Add(Selection.Range,
wdFieldQuote, "text")
fField.Code.Text = " ADDIN "
fField.Result.Text = ""
' add the footnote
Set note = ActiveDocument.Footnotes.Add(Range:=fField.Result)
note.Range.Text = "Hello"
End Sub
Run this and you have a field whose result is a reference to a
footnote whose content is "Hello". Cool.
But alas, all is not well. Manually add another footnote to the
document. Put "Goodbye" into the footnote.
Now run this routine:
Sub scanNote()
MsgBox ActiveDocument.Fields(1).Result.Footnotes.Count
For Each myfootnote In ActiveDocument.Fields(1).Result.Footnotes
MsgBox myfootnote.Range.Text
Next myfootnote
End Sub
The first MsgBox says that there is one footnote in the result of the
field. That's right.
But the loop then iterates through all footnotes in the whole
document. That's wrong. This seems a bug in ADDIN, but since that
field is a secret of sorts anyway (and maybe I wasn't supposed to be
able to put a note reference in it in the first place), I guess I
can't complain.
My problem is that given the field, I need to go look at the content
of the footnote, but I can't.
Any suggestions appreciated. (I'm using Word 2003 but I need this to
work with newer versions also.)