Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2006

Tip: Looking for answers? Try searching our database.

How to check if text wraps in a table cell

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JS - 28 Sep 2006 21:13 GMT
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
Jean-Guy Marcil - 29 Sep 2006 02:40 GMT
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.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Jay Freedman - 29 Sep 2006 04:20 GMT
>JS was telling us:
>JS nous racontait que :
[quoted text clipped - 10 lines]
>You could determine a default height (When there is only one line of text)
>and then compare the current height with that value.

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        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
Jean-Guy Marcil - 29 Sep 2006 12:20 GMT
Jay Freedman was telling us:
Jay Freedman nous racontait que :

>> JS was telling us:
>> JS nous racontait que :
[quoted text clipped - 27 lines]
>
> 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
'_______________________________________

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Jean-Guy Marcil - 29 Sep 2006 12:57 GMT
Jean-Guy Marcil was telling us:
Jean-Guy Marcil nous racontait que :

> Jay Freedman was telling us:
> Jay Freedman nous racontait que :
[quoted text clipped - 34 lines]
> 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!

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

JS - 30 Sep 2006 19:46 GMT
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

> Jean-Guy Marcil was telling us:
> Jean-Guy Marcil nous racontait que :
[quoted text clipped - 53 lines]
> jmarcilREMOVE@CAPSsympatico.caTHISTOO
> Word MVP site: http://www.word.mvps.org
Helmut Weber - 29 Sep 2006 14:07 GMT
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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Helmut Weber - 30 Sep 2006 13:46 GMT
hmm...

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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

JS - 30 Sep 2006 19:44 GMT
Hi Helmut:
Lovely - It works! thanks so much for your help :)
Rgds, JS

> Hi JS,
>
[quoted text clipped - 32 lines]
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"

Rate this thread:






 
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



©2008 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.