I am writing a program in VB6 which adds footnotes to a Word document.
My problem arises when there is no footnote text to add to the Word
document. There is an array, Foot, which was previously loaded with data.
It contains two fields :-
Mark contains the reference string
Rng contains a range object.
If the Rng field was not loaded with data previously I detect this with Not
IsObjectValid.
I then need to create a valid Range object and put an error message in its
Text property.
How do I create a valid Rng field in the Foot array? My latest attempt, like
lots of previous attempts give an error.
Set Rng = ActiveDocument.Range(Start:=Selection.Start, End:=REnd)
FtNum = Val(FootNum)
If Not IsObjectValid(Foot(FtNum).Rng) Then
Set Foot(FtNum).Rng = New Range ' GIVES AN ERROR!!!
Foot(FtNum).Rng.Text = "*** NO TEXT FOR THIS FOOTNOTE IN MAGNA
FOOTNOTE FILE ***"
End If
If chkAutoNum.Value Then
ActiveDocument.Footnotes.Add Range:=Selection.Range,
Reference:="", Text:=Foot(FtNum).Rng.Text
Else
ActiveDocument.Footnotes.Add Range:=Selection.Range,
Reference:=Foot(FtNum).Mark, Text:=Foot(FtNum).Rng.Text
End If
Rng.Delete
>I am writing a program in VB6 which adds footnotes to a Word document.
> My problem arises when there is no footnote text to add to the Word
[quoted text clipped - 10 lines]
> How do I create a valid Rng field in the Foot array? My latest attempt, like
> lots of previous attempts give an error.
You can't create Range objects (they don't appear in the list when you type Set
Rng = New ...). A range object always refers to existing text in the document,
even if it just a blank spot.
When you build your array, the range objects are references to existing ranges
in the document, not separate free standing range objects. I don't know how you
are building your array, but it sounds like certain elements have no range,
because there is no footnote in the source, or something like that.
Since your later code goes about adding all the footnotes to the document
anyway, it seems like you could just change your array to hold FootText as a
string. Then you can assign FootText either the text of an existing range, or
your "no text for this footnote" message. Your code for adding the footnotes
would work fine, substituting Text:=Foot(FtNum).FootText for the text
assignment.
richard - 27 Feb 2006 08:19 GMT
Thanks, Steve, I don't know how I got into such a mess but you've put me
back on the straight and narrow!
Cheers
Richard
> >I am writing a program in VB6 which adds footnotes to a Word document.
> > My problem arises when there is no footnote text to add to the Word
[quoted text clipped - 26 lines]
> would work fine, substituting Text:=Foot(FtNum).FootText for the text
> assignment.