Number of current 'line' (para) 
Author Message
 Number of current 'line' (para)

I'm using Word97 to extract information from software source files,
and opening the (text) file in Word to analyse it. Occasionally, I
need to direct the user to a problem in a particular line (a Word
paragraph).

Hunt as I could, I couldn't find something that returned a paragraph
number from a range. I tried
Rng.Information(wdFirstCharacterLineNumber), but it seemed to top
out at 999. I'm currently using Range(0,Rng.Start).Paragraphs.Count
and it works OK, but it seems a longwinded way of going about it.

Andrew
--
Andrew Gabb

phone: +61 8 8342-1021, fax: +61 8 8269-3280
-----



Wed, 16 Apr 2003 21:15:24 GMT  
 Number of current 'line' (para)

Hi Andrew,

Take a look here

http://www.mvps.org/word/FAQs/MacrosVBA/GetIndexNoOfPara.htm

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
Word FAQs at http://www.multilinker.com/wordfaq
Please post any follow-up in the newsgroup. I do not reply to Word questions
by email


Quote:
> I'm using Word97 to extract information from software source files,
> and opening the (text) file in Word to analyse it. Occasionally, I
> need to direct the user to a problem in a particular line (a Word
> paragraph).

> Hunt as I could, I couldn't find something that returned a paragraph
> number from a range. I tried
> Rng.Information(wdFirstCharacterLineNumber), but it seemed to top
> out at 999. I'm currently using Range(0,Rng.Start).Paragraphs.Count
> and it works OK, but it seems a longwinded way of going about it.

> Andrew
> --
> Andrew Gabb

> phone: +61 8 8342-1021, fax: +61 8 8269-3280
> -----



Wed, 16 Apr 2003 23:16:49 GMT  
 Number of current 'line' (para)

Quote:

> Hi Andrew,

> Take a look here

> http://www.mvps.org/word/FAQs/MacrosVBA/GetIndexNoOfPara.htm

Thanks, Jonathan.

Hmmm, they both look far less elegant than what I suggested. I also
suspect they're slower. The binary method uses log2(N) calls, which
may be faster, but superficially it needs to count for each call.

Who knows how VBA counts.

Anyway, I think you answered my implicit question. With 'no'.

Andrew

Quote:


> > I'm using Word97 to extract information from software source files,
> > and opening the (text) file in Word to analyse it. Occasionally, I
> > need to direct the user to a problem in a particular line (a Word
> > paragraph).

> > Hunt as I could, I couldn't find something that returned a paragraph
> > number from a range. I tried
> > Rng.Information(wdFirstCharacterLineNumber), but it seemed to top
> > out at 999. I'm currently using Range(0,Rng.Start).Paragraphs.Count
> > and it works OK, but it seems a longwinded way of going about it.

> > Andrew
> > --
> > Andrew Gabb

> > phone: +61 8 8342-1021, fax: +61 8 8269-3280
> > -----

--
Andrew Gabb

phone: +61 8 8342-1021, fax: +61 8 8269-3280
-----


Thu, 17 Apr 2003 21:56:23 GMT  
 Number of current 'line' (para)

Am I correct in understanding that a Word Paragraph is actually a line?
I've been using rather longwinded means of doing things not having a
lines.count function!!
Mark.


Quote:

> > Hi Andrew,

> > Take a look here

> > http://www.mvps.org/word/FAQs/MacrosVBA/GetIndexNoOfPara.htm

> Thanks, Jonathan.

> Hmmm, they both look far less elegant than what I suggested. I also
> suspect they're slower. The binary method uses log2(N) calls, which
> may be faster, but superficially it needs to count for each call.

> Who knows how VBA counts.

> Anyway, I think you answered my implicit question. With 'no'.

> Andrew



> > > I'm using Word97 to extract information from software source files,
> > > and opening the (text) file in Word to analyse it. Occasionally, I
> > > need to direct the user to a problem in a particular line (a Word
> > > paragraph).

> > > Hunt as I could, I couldn't find something that returned a paragraph
> > > number from a range. I tried
> > > Rng.Information(wdFirstCharacterLineNumber), but it seemed to top
> > > out at 999. I'm currently using Range(0,Rng.Start).Paragraphs.Count
> > > and it works OK, but it seems a longwinded way of going about it.

> > > Andrew
> > > --
> > > Andrew Gabb

> > > phone: +61 8 8342-1021, fax: +61 8 8269-3280
> > > -----

> --
> Andrew Gabb

> phone: +61 8 8342-1021, fax: +61 8 8269-3280
> -----



Fri, 18 Apr 2003 08:15:34 GMT  
 Number of current 'line' (para)
Hi Mark,

Not really, no. A line of text doesn't have much of a status within Word, as
its length depends on such things as column width, font and even printer
driver. About the only way you can grab a line of text is to position the
cursor on the line you want, and then select the text marked by the \Line
predefined bookmark.

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
Word FAQs at http://www.multilinker.com/wordfaq
Please post any follow-up in the newsgroup. I do not reply to Word questions
by email


Quote:
> Am I correct in understanding that a Word Paragraph is actually a line?
> I've been using rather longwinded means of doing things not having a
> lines.count function!!
> Mark.




> > > Hi Andrew,

> > > Take a look here

> > > http://www.mvps.org/word/FAQs/MacrosVBA/GetIndexNoOfPara.htm

> > Thanks, Jonathan.

> > Hmmm, they both look far less elegant than what I suggested. I also
> > suspect they're slower. The binary method uses log2(N) calls, which
> > may be faster, but superficially it needs to count for each call.

> > Who knows how VBA counts.

> > Anyway, I think you answered my implicit question. With 'no'.

> > Andrew



> > > > I'm using Word97 to extract information from software source files,
> > > > and opening the (text) file in Word to analyse it. Occasionally, I
> > > > need to direct the user to a problem in a particular line (a Word
> > > > paragraph).

> > > > Hunt as I could, I couldn't find something that returned a paragraph
> > > > number from a range. I tried
> > > > Rng.Information(wdFirstCharacterLineNumber), but it seemed to top
> > > > out at 999. I'm currently using Range(0,Rng.Start).Paragraphs.Count
> > > > and it works OK, but it seems a longwinded way of going about it.

> > > > Andrew
> > > > --
> > > > Andrew Gabb

> > > > phone: +61 8 8342-1021, fax: +61 8 8269-3280
> > > > -----

> > --
> > Andrew Gabb

> > phone: +61 8 8342-1021, fax: +61 8 8269-3280
> > -----



Fri, 18 Apr 2003 09:22:51 GMT  
 Number of current 'line' (para)

If you need to know the paragraph index then do not use the paragraph
collection.

You could step through the paragraphs using a For...Next statement.

For i = 1 To ActiveDocument.Paragraphs.Count

    With ActiveDocument.Paragraphs(i)
        ' Code here
    End With

Next i

Mark Baird


Quote:
> I'm using Word97 to extract information from software source files,
> and opening the (text) file in Word to analyse it. Occasionally, I
> need to direct the user to a problem in a particular line (a Word
> paragraph).

> Hunt as I could, I couldn't find something that returned a paragraph
> number from a range. I tried
> Rng.Information(wdFirstCharacterLineNumber), but it seemed to top
> out at 999. I'm currently using Range(0,Rng.Start).Paragraphs.Count
> and it works OK, but it seems a longwinded way of going about it.

> Andrew
> --
> Andrew Gabb

> phone: +61 8 8342-1021, fax: +61 8 8269-3280
> -----



Sat, 19 Apr 2003 07:39:16 GMT  
 Number of current 'line' (para)
Hi Andrew

Maybe I'm missing something but why not simply use Rng.Paragraphs(1),
as suggested in the article Jonathan linked to?

Regards

Dave


Quote:

> Hi Andrew,

> Take a look here

> http://www.mvps.org/word/FAQs/MacrosVBA/GetIndexNoOfPara.htm

Thanks, Jonathan.

Hmmm, they both look far less elegant than what I suggested. I also
suspect they're slower. The binary method uses log2(N) calls, which may
be faster, but superficially it needs to count for each call.

Who knows how VBA counts.

Anyway, I think you answered my implicit question. With 'no'.

Andrew

Quote:


> > I'm using Word97 to extract information from software source files,
> > and opening the (text) file in Word to analyse it. Occasionally, I
> > need to direct the user to a problem in a particular line (a Word
> > paragraph).

> > Hunt as I could, I couldn't find something that returned a paragraph
> > number from a range. I tried
> > Rng.Information(wdFirstCharacterLineNumber), but it seemed to top
> > out at 999. I'm currently using Range(0,Rng.Start).Paragraphs.Count
> > and it works OK, but it seems a longwinded way of going about it.

> > Andrew

Sent via Deja.com http://www.deja.com/
Before you buy.


Sat, 19 Apr 2003 19:08:10 GMT  
 Number of current 'line' (para)
Hi Mark

This paragraph, like most paragraphs one comes accros in the real
world, consists of several lines. In fact a paragraph can consist of
any number of lines.

This is the second paragraph of my reply, but it's *not* the second
line!

Hope that helps

Regards

Dave



Am I correct in understanding that a Word Paragraph is actually a line?
I've been using rather longwinded means of doing things not having a
lines.count function!!
Mark.

Sent via Deja.com http://www.deja.com/
Before you buy.



Sat, 19 Apr 2003 19:11:23 GMT  
 Number of current 'line' (para)

Quote:

> Am I correct in understanding that a Word Paragraph is actually a line?
> I've been using rather longwinded means of doing things not having a
> lines.count function!!
> Mark.

When you read a text file prepared with a text editor into Word,
each line in the text file becomes a paragraph in Word (and may
wrap, depending on the document settings).

When I referred to 'line', I was talking about text file lines, not
Word lines.

Andrew
--
Andrew Gabb

phone: +61 8 8342-1021, fax: +61 8 8269-3280
-----



Sat, 19 Apr 2003 21:11:34 GMT  
 Number of current 'line' (para)

Quote:

> Maybe I'm missing something but why not simply use Rng.Paragraphs(1),
> as suggested in the article Jonathan linked to?

Because this returns the paragraph itself, and I need the index of
the paragraph.

As I stated, I currently use Range(0,Rng.Start).Paragraphs.Count
which works fine. I was just surprised that it wasn't easier.

To help in understanding how this work, the expression above forms a
new range from the start of the document (0) to the start of the
current range (Rng.Start). It then counts the paragraphs in this new
range, which is the number I want.

Andrew

Quote:


> > Hi Andrew,

> > Take a look here

> > http://www.mvps.org/word/FAQs/MacrosVBA/GetIndexNoOfPara.htm

> Thanks, Jonathan.

> Hmmm, they both look far less elegant than what I suggested. I also
> suspect they're slower. The binary method uses log2(N) calls, which may
> be faster, but superficially it needs to count for each call.

> Who knows how VBA counts.

> Anyway, I think you answered my implicit question. With 'no'.

> Andrew



> > > I'm using Word97 to extract information from software source files,
> > > and opening the (text) file in Word to analyse it. Occasionally, I
> > > need to direct the user to a problem in a particular line (a Word
> > > paragraph).

> > > Hunt as I could, I couldn't find something that returned a paragraph
> > > number from a range. I tried
> > > Rng.Information(wdFirstCharacterLineNumber), but it seemed to top
> > > out at 999. I'm currently using Range(0,Rng.Start).Paragraphs.Count
> > > and it works OK, but it seems a longwinded way of going about it.

> > > Andrew

> Sent via Deja.com http://www.deja.com/
> Before you buy.

--
Andrew Gabb

phone: +61 8 8342-1021, fax: +61 8 8269-3280
-----


Sat, 19 Apr 2003 21:17:59 GMT  
 Number of current 'line' (para)

Hi Andrew

Quote:

> As I stated, I currently use Range(0,Rng.Start).Paragraphs.Count
> which works fine. I was just surprised that it wasn't easier.

That's a neater way that I had thought of, at least in terms of the code
being shorter. I've learned something new about Word today. Thanks!

I must do some speed comparisons between them. It looks like it *ought* to
be quicker, but I have hard experience that proves you just shouldn't make
those kinds of assumptions with Word!

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
Word FAQs at http://www.multilinker.com/wordfaq
Please post any follow-up in the newsgroup. I do not reply to Word questions
by email



Sat, 19 Apr 2003 22:52:26 GMT  
 Number of current 'line' (para)

Hi Andrew,

Text file lines, as you describe them, are paragraphs in Word.

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
Word FAQs at http://www.multilinker.com/wordfaq
Please post any follow-up in the newsgroup. I do not reply to Word questions
by email


Quote:

> > Am I correct in understanding that a Word Paragraph is actually a line?
> > I've been using rather longwinded means of doing things not having a
> > lines.count function!!
> > Mark.

> When you read a text file prepared with a text editor into Word,
> each line in the text file becomes a paragraph in Word (and may
> wrap, depending on the document settings).

> When I referred to 'line', I was talking about text file lines, not
> Word lines.

> Andrew
> --
> Andrew Gabb

> phone: +61 8 8342-1021, fax: +61 8 8269-3280
> -----



Sat, 19 Apr 2003 22:48:42 GMT  
 Number of current 'line' (para)
Hi Jonathan, Andrew

Quote:
> > As I stated, I currently use Range(0,Rng.Start).Paragraphs.Count
> > which works fine. I was just surprised that it wasn't easier.

> That's a neater way that I had thought of, at least in terms of the code
> being shorter. I've learned something new about Word today. Thanks!

Thanks here too :-) Very neat.

Quote:
> I must do some speed comparisons between them. It looks like it *ought* to
> be quicker, but I have hard experience that proves you just shouldn't make
> those kinds of assumptions with Word!

30,000 paragraph document, retrieving the index of the the last paragraph:

- 1st method on mvps.org - gave up 12 minutes into the macro by which time
it had reached the ~6000th paragraph

- 2nd method - 20 seconds

- Andrew's method - 2 seconds !

Andrew wins ;-)

--
ibby



Sat, 19 Apr 2003 23:49:16 GMT  
 Number of current 'line' (para)
I'll update the article and credit Andrew for the code (assuming Andrew
has no objection, of course). In view of its simplicity, I suggest
the "first method" (cycling thruugh the collection) be dropped from the
article altogether - it was only included because it was easy to follow.

Regards

Dave



Hi Jonathan, Andrew

Quote:
> > As I stated, I currently use Range(0,Rng.Start).Paragraphs.Count
> > which works fine. I was just surprised that it wasn't easier.

> That's a neater way that I had thought of, at least in terms of the
code
> being shorter. I've learned something new about Word today. Thanks!

Thanks here too :-) Very neat.

Quote:
> I must do some speed comparisons between them. It looks like it
*ought* to
> be quicker, but I have hard experience that proves you just shouldn't
make
> those kinds of assumptions with Word!

30,000 paragraph document, retrieving the index of the last paragraph:

- 1st method on mvps.org - gave up 12 minutes into the macro by which
time it had reached the ~6000th paragraph

- 2nd method - 20 seconds

- Andrew's method - 2 seconds !

Andrew wins ;-)

--
ibby

Sent via Deja.com http://www.deja.com/
Before you buy.



Sun, 20 Apr 2003 03:02:51 GMT  
 Number of current 'line' (para)

Hi again Andrew

When I tried using Range(0,Rng.Start).Paragraphs.Count, then if the start of
the range was at the start of a paragraph, it often returned one less than
the index - e.g. if the start of the range was at the start of paragraph 4,
it returned 3. The following seems always to work when I try it:

MsgBox ActiveDocument.Range(0, Rng.Paragraphs(1).Range.End).Paragraphs.Count

Any comments?

Regards

Dave


| > Maybe I'm missing something but why not simply use Rng.Paragraphs(1),
| > as suggested in the article Jonathan linked to?
|
| Because this returns the paragraph itself, and I need the index of
| the paragraph.
|
| As I stated, I currently use Range(0,Rng.Start).Paragraphs.Count
| which works fine. I was just surprised that it wasn't easier.
|
| To help in understanding how this work, the expression above forms a
| new range from the start of the document (0) to the start of the
| current range (Rng.Start). It then counts the paragraphs in this new
| range, which is the number I want.
|
| Andrew
|


| > >
| > > Hi Andrew,
| > >
| > > Take a look here
| > >
| > > http://www.mvps.org/word/FAQs/MacrosVBA/GetIndexNoOfPara.htm
| >
| > Thanks, Jonathan.
| >
| > Hmmm, they both look far less elegant than what I suggested. I also
| > suspect they're slower. The binary method uses log2(N) calls, which may
| > be faster, but superficially it needs to count for each call.
| >
| > Who knows how VBA counts.
| >
| > Anyway, I think you answered my implicit question. With 'no'.
| >
| > Andrew
| >


| > > > I'm using Word97 to extract information from software source files,
| > > > and opening the (text) file in Word to analyse it. Occasionally, I
| > > > need to direct the user to a problem in a particular line (a Word
| > > > paragraph).
| > > >
| > > > Hunt as I could, I couldn't find something that returned a paragraph
| > > > number from a range. I tried
| > > > Rng.Information(wdFirstCharacterLineNumber), but it seemed to top
| > > > out at 999. I'm currently using Range(0,Rng.Start).Paragraphs.Count
| > > > and it works OK, but it seems a longwinded way of going about it.
| > > >
| > > > Andrew
| >
| > Sent via Deja.com http://www.deja.com/
| > Before you buy.
|
| --
| Andrew Gabb

| phone: +61 8 8342-1021, fax: +61 8 8269-3280
| -----



Sun, 20 Apr 2003 07:04:25 GMT  
 
 [ 16 post ]  Go to page: [1] [2]

 Relevant Pages 

1. numbered para's and numbered lists?

2. Word:Current Para Number

3. Word '97 Line Number in VB 6.0

4. Word '97 Line Number from VB 6.0

5. para para para money

6. Macro doesn't get rid of spaces before para mark

7. 'no current record' message

8. 'No current record'

9. No Current Record - Error '3021'

10. 'no current record' error

11. EOF/ 'No Current Record' problem

12. Current Line Number in an Access Module

 

 
Powered by phpBB® Forum Software