Solved

VBA for Word: How to determine the line count of a paragraph?

Posted on 2001-08-30
10
691 Views
Last Modified: 2008-02-26
How can I determine the number of lines in a paragraph? In the VBA help files I didn't find a property like e.g. "LineCount" nor any method to retrieve it. Is there a way at all to do this?
0
Comment
Question by:rernst
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 6439563
Duplicated question, please delete it.
0
 
LVL 17

Expert Comment

by:calacuccia
ID: 6439676
ryancys, I think you got the wrong question, I don't see any duplicate (or remst already deleted the other one).

remst,

Try this:

Sub CountLinesParagraph(parNumber As Long)
Dim noLines As Long
With ActiveDocument.Paragraphs(parNumber)
noLines ActiveDocument.Range(Start:=.Range.Start, End:=.Range.Start).Information(wdFirstCharacterLineNumber) - ActiveDocument.Range(Start:=.Range.End - 1, End:=.Range.End - 1).Information(wdFirstCharacterLineNumber)
End With
End Sub
0
 
LVL 17

Expert Comment

by:calacuccia
ID: 6439678
Correction

Sub CountLinesParagraph(parNumber As Long)
Dim noLines As Long
With ActiveDocument.Paragraphs(parNumber)
     noLines = ActiveDocument.Range(Start:=.Range.Start, End:=.Range.Start).Information(wdFirstCharacterLineNumber) _
    - ActiveDocument.Range(Start:=.Range.End - 1, End:=.Range.End - 1).Information(wdFirstCharacterLineNumber)
End With
End Sub
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 52

Expert Comment

by:Ryan Chong
ID: 6439690
Hi calacuccia,

FYI, glad that you only see 1 similar question here. : )
0
 

Author Comment

by:rernst
ID: 6439774
Hi calacuccia,

 I tried it. However "nolines" is always either 0 or negative.
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6439806
hope you should subtract it reverse order, if I understood properly.

hey, look at the grading history..

0
 
LVL 17

Accepted Solution

by:
calacuccia earned 100 total points
ID: 6439816
Oops, you're right Yalli_An.

Sub CountLinesParagraph(parNumber As Long)
Dim noLines As Long
With ActiveDocument.Paragraphs(parNumber)
    noLines = ActiveDocument.Range(Start:=.Range.End, End:=.Range.End).Information(wdFirstCharacterLineNumber) _
   - ActiveDocument.Range(Start:=.Range.Start - 1, End:=.Range.Start - 1).Information(wdFirstCharacterLineNumber)
End With
End Sub
0
 

Author Comment

by:rernst
ID: 6439841
Ok. This version now works:

With ActiveDocument.Paragraphs(parNumber)
    noLines = ActiveDocument.Range(Start:=.Range.End, End:=.Range.End).Information(wdFirstCharacterLineNumber) - ActiveDocument.Range(Start:=.Range.Start, End:=.Range.Start).Information(wdFirstCharacterLineNumber)
End With

It gives me a runtime error '4608' on the last paragraph, though. Any idea why?
0
 
LVL 17

Expert Comment

by:calacuccia
ID: 6439955
Sorry, I  should have tested it more thoroughly.

Try this version

Sub CountLinesParagraph(parNumber As Long)
Dim noLines As Long
With ActiveDocument.Paragraphs(parNumber)
    noLines = ActiveDocument.Range(Start:=.Range.End - 1, End:=.Range.End - 1).Information(wdFirstCharacterLineNumber) _
   - ActiveDocument.Range(Start:=.Range.Start, End:=.Range.Start).Information(wdFirstCharacterLineNumber) + 1
End With
End Sub
0
 

Author Comment

by:rernst
ID: 6440327
Thank you calacuccia, that's it finally.
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month6 days, 10 hours left to enroll

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question