Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables,microsoft.public.word.vba.general
Ed
 
Posts: n/a
Default How many lines used in a table cell?

Is there a simple way to tell from VBA code how many lines of text are in a
table cell?

Ed


  #2   Report Post  
Posted to microsoft.public.word.tables,microsoft.public.word.vba.general
Jezebel
 
Posts: n/a
Default How many lines used in a table cell?

Not simple, no. One method is to iterate the characters of the text, and
check .Information(wdVerticalPositionRelativeToPage) for each: the number of
different values you get is the number of lines.





"Ed" wrote in message
...
Is there a simple way to tell from VBA code how many lines of text are in
a
table cell?

Ed




  #3   Report Post  
Posted to microsoft.public.word.tables,microsoft.public.word.vba.general
Jay Freedman
 
Posts: n/a
Default How many lines used in a table cell?

Another way is to put the Selection at the beginning of the cell and
count how many times you can repeat the .MoveDown method until the
Selection either goes into the next row or drops out of the table.
Unfortunately, you have to use the Selection because the Range object
doesn't have a .MoveDown method.

Sub LinesInCell()
Dim nLines As Long, nCurrRow As Long
Dim rgSaveSel As Range
Set rgSaveSel = Selection.Range

If Not Selection.Information(wdWithInTable) Then
MsgBox "Not in a table"
Exit Sub
End If

With Selection
.Cells(1).Select
.Collapse wdCollapseStart
nCurrRow = .Information(wdEndOfRangeRowNumber)
nLines = 0

Do
nLines = nLines + 1
.MoveDown unit:=wdLine, Count:=1, Extend:=False
If Not .Information(wdWithInTable) Then Exit Do
Loop Until .Information(wdEndOfRangeRowNumber) nCurrRow
End With

MsgBox nLines & " line(s)"
rgSaveSel.Select
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Fri, 3 Feb 2006 09:34:37 +1100, "Jezebel"
wrote:

Not simple, no. One method is to iterate the characters of the text, and
check .Information(wdVerticalPositionRelativeToPage) for each: the number of
different values you get is the number of lines.


"Ed" wrote in message
...
Is there a simple way to tell from VBA code how many lines of text are in
a
table cell?

Ed

  #4   Report Post  
Posted to microsoft.public.word.tables,microsoft.public.word.vba.general
Jezebel
 
Posts: n/a
Default How many lines used in a table cell?

There might be a rigorous and elegant way to do it using something along the
lines of

activedocument.ActiveWindow.Panes(x).Pages(y).Rect angles(z).Lines(t).Rectangles.Count

But I have not the faintest idea how this bit of the object model is
supposed to work.





"Jay Freedman" wrote in message
...
Another way is to put the Selection at the beginning of the cell and
count how many times you can repeat the .MoveDown method until the
Selection either goes into the next row or drops out of the table.
Unfortunately, you have to use the Selection because the Range object
doesn't have a .MoveDown method.

Sub LinesInCell()
Dim nLines As Long, nCurrRow As Long
Dim rgSaveSel As Range
Set rgSaveSel = Selection.Range

If Not Selection.Information(wdWithInTable) Then
MsgBox "Not in a table"
Exit Sub
End If

With Selection
.Cells(1).Select
.Collapse wdCollapseStart
nCurrRow = .Information(wdEndOfRangeRowNumber)
nLines = 0

Do
nLines = nLines + 1
.MoveDown unit:=wdLine, Count:=1, Extend:=False
If Not .Information(wdWithInTable) Then Exit Do
Loop Until .Information(wdEndOfRangeRowNumber) nCurrRow
End With

MsgBox nLines & " line(s)"
rgSaveSel.Select
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Fri, 3 Feb 2006 09:34:37 +1100, "Jezebel"
wrote:

Not simple, no. One method is to iterate the characters of the text, and
check .Information(wdVerticalPositionRelativeToPage) for each: the number
of
different values you get is the number of lines.


"Ed" wrote in message
...
Is there a simple way to tell from VBA code how many lines of text are
in
a
table cell?

Ed



  #5   Report Post  
Posted to microsoft.public.word.tables,microsoft.public.word.vba.general
Jean-Guy Marcil
 
Posts: n/a
Default How many lines used in a table cell?

Jezebel was telling us:
Jezebel nous racontait que :

There might be a rigorous and elegant way to do it using something
along the lines of

activedocument.ActiveWindow.Panes(x).Pages(y).Rect angles(z).Lines(t).Rectangles.Count

But I have not the faintest idea how this bit of the object model is
supposed to work.


I believe that the rectangle object usually refers to elements on the page,
such as header, footer, textboxes, main story, etc.

I do not think it is possible to use this to get the line count in a cell...
but it is 3:00 am and I might be totally wrong!


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
ISTOO
Word MVP site:
http://www.word.mvps.org




  #6   Report Post  
Posted to microsoft.public.word.tables,microsoft.public.word.vba.general
Jezebel
 
Posts: n/a
Default How many lines used in a table cell?

I've followed it far enough to establish that you can retrieve the
individual lines on the page; but quite how, I don'tknow.


"Jean-Guy Marcil" NoSpam@LeaveMeAlone wrote in message
...
Jezebel was telling us:
Jezebel nous racontait que :

There might be a rigorous and elegant way to do it using something
along the lines of

activedocument.ActiveWindow.Panes(x).Pages(y).Rect angles(z).Lines(t).Rectangles.Count

But I have not the faintest idea how this bit of the object model is
supposed to work.


I believe that the rectangle object usually refers to elements on the
page, such as header, footer, textboxes, main story, etc.

I do not think it is possible to use this to get the line count in a
cell... but it is 3:00 am and I might be totally wrong!


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
ISTOO
Word MVP site:
http://www.word.mvps.org



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to wrap text from cell to cell in a table. Jon Coulson Tables 2 August 8th 05 09:12 PM
Placing 1st table into a cell within 2nd table kathryngriffin1962 Tables 2 June 2nd 05 04:09 AM
Table headers/footers and layout Keith Page Layout 1 April 8th 05 07:37 PM
Table AutoFormats vs. Table Styles confusion Tony Jollans Tables 5 March 6th 05 07:18 PM
word table cell resize or word table cell size change or word table change cell size [email protected] Tables 0 January 13th 05 09:55 PM


All times are GMT +1. The time now is 11:47 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"