How to check if text wraps in a table cell

J

JS

Hi All:
I need to know if existing text in a table's cell is wrapping (i.e., too
long to fit in a cell, this wrapping and doubling the height of the cell -
and entire row of the table). I could not find a Cell property that tells
if a cell wrapped or not - is this possible?
TYA, JS
 
J

Jean-Guy Marcil

JS was telling us:
JS nous racontait que :
Hi All:
I need to know if existing text in a table's cell is wrapping (i.e.,
too long to fit in a cell, this wrapping and doubling the height of
the cell - and entire row of the table). I could not find a Cell
property that tells if a cell wrapped or not - is this possible?
TYA, JS

There is no such property.

You could determine a default height (When there is only one line of text)
and then compare the current height with that value.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jay Freedman

JS was telling us:
JS nous racontait que :


There is no such property.

You could determine a default height (When there is only one line of text)
and then compare the current height with that value.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org

It's worse than that: If the row height isn't specified in the Table >
Table Properties > Row dialog, then the row's .Height property will
return a value of 9999999 (which is the constant wdUndefined). If that
happens, the only way remaining is to get the property
..Information(wdVerticalPositionRelativeToPage) for the current row's
range, get the same property for the next row's range, and take the
difference (checking first that they aren't on different pages).

The code for the general case is quite a mess.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
J

Jean-Guy Marcil

Jay Freedman was telling us:
Jay Freedman nous racontait que :
It's worse than that: If the row height isn't specified in the Table >
Table Properties > Row dialog, then the row's .Height property will
return a value of 9999999 (which is the constant wdUndefined). If that
happens, the only way remaining is to get the property
.Information(wdVerticalPositionRelativeToPage) for the current row's
range, get the same property for the next row's range, and take the
difference (checking first that they aren't on different pages).

The code for the general case is quite a mess.

Right, had forgotten about that.
In that case, if there aren't any merged cells, we can use this workaround:

'_______________________________________
Sub GetRowHeight()

Dim lngRowHeightType As Long
Dim sngRowHeight As Single
Dim tblTarget As Table

Set tblTarget = ActiveDocument.Tables(1)

With tblTarget.Rows(5)
'Get Height
If .Height = wdUndefined Then
'Save current setting
lngRowHeightType = .HeightRule
.HeightRule = wdRowHeightExactly
sngRowHeight = .Height
.HeightRule = lngRowHeightType
Else
sngRowHeight = .Height
End If
MsgBox Format(PointsToInches(sngRowHeight), "#0.00") & " inches tall"
End With

End Sub
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jean-Guy Marcil

Jean-Guy Marcil was telling us:
Jean-Guy Marcil nous racontait que :
Jay Freedman was telling us:
Jay Freedman nous racontait que :


Right, had forgotten about that.
In that case, if there aren't any merged cells, we can use this
workaround:

Ooops... forget about that...
I just realized that this always gives the same result, i.e 12 points high,
regardless of the actual cell height.

I thought I could just adapt some code I had for dealing with table width...
but apparently not!

Sorry about that!

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
H

Helmut Weber

Hi JS,

how about this one:

Public Function WrappedTextinCell(rCll As Range) As Boolean
Dim oPrg As Paragraph
WrappedTextinCell = False
If Len(rCll) = 2 Then Exit Function
rCll.End = rCll.End - 1
If rCll.Paragraphs.Count = 1 Then
If rCll.ComputeStatistics(wdStatisticLines) > 0 Then
WrappedTextinCell = True
Exit Function
End If
End If
For Each oPrg In rCll.Paragraphs
If oPrg.Range.ComputeStatistics(wdStatisticLines) > 1 Then
WrappedTextinCell = True
Exit Function
End If
Next
End Function

Sub WrapTest()
MsgBox WrappedTextinCell(selection.Cells(1).Range)
End Sub

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
H

Helmut Weber

hmm...

If rCll.Paragraphs.Count = 0 Then ' <<<
If rCll.ComputeStatistics(wdStatisticLines) > 0 Then
WrappedTextinCell = True
Exit Function
End If
End If

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
J

JS

Hi Jean-Guy and Jay:
Thanks you for your effort in lokking into this - I appreciate you time.
I've tested Helmut's solution and it works for me :)
Again, thanks for your help - rgds, JS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top