Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / February 2006



Tip: Looking for answers? Try searching our database.

Creating a new range object for Word

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
richard - 23 Feb 2006 21:15 GMT
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
Steve Gerrard - 25 Feb 2006 18:26 GMT
>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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.