Problem: How to judge word wrap has happened in a cell ?

D

David W

If i find word wrap has happened in a cell, i'll need merge some right
columns to avoid word wrap. So anyone could give me some suggestions ?

Thanks in advance!
 
J

Jean-Guy Marcil

David W was telling us:
David W nous racontait que :
If i find word wrap has happened in a cell, i'll need merge some right
columns to avoid word wrap. So anyone could give me some suggestions ?

Play around with this:

'_______________________________________
Dim cellRge As Range

Set cellRge = Selection.Cells(1).Range

With cellRge
If .Characters.Count > 1 Then
If .Characters(1). _
Information(wdVerticalPositionRelativeToPage) < _
.Characters(.Characters.Count - 1). _
Information(wdVerticalPositionRelativeToPage) Or _
.Paragraphs.Count > 1 Then
MsgBox "Cell text is on at least two lines, merge!"
Else
MsgBox "Cell text is on one line, no merge!"
End If
Else
MsgBox "Cell is empty, no merge!"
End If
End With
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
[email protected]
Word MVP site: http://www.word.mvps.org
 
C

Chuck

Sorry, the "rngCell.select" lines in the code I posted aren't necessary.
They're left over from when I was testing the code. Delete them if you want
shouldn't make a difference.
 
C

Chuck

Here's a modification to Jean-Guy's code that takes account of cells in rows
that span page breaks. If the beginning of the cell is on one page and the
end on another, it's a multi-line cell. Note this doesn't take account of
situations where the cell ends with a paragraph marker. You could test for
that if you didn't want to count the paragraph marker as creating a "new
line".

Sub CountLinesInCell()

Dim rngCell As Range
Dim x As Long
Dim y As Long

Set rngCell = Selection.Cells(1).Range
rngCell.Select

With rngCell
.Collapse wdCollapseStart
x = .Information(wdActiveEndPageNumber)
End With

Set rngCell = Selection.Cells(1).Range
rngCell.Select

With rngCell
.End = .End - 1
y = .Information(wdActiveEndPageNumber)
End With

If y - x <> 0 Then
MsgBox "Multiline cell"
Else
Set rngCell = Selection.Cells(1).Range
With rngCell
If .Characters.Count > 1 Then
If .Characters(1). _
Information(wdVerticalPositionRelativeToPage) < _
.Characters(.Characters.Count - 1). _
Information(wdVerticalPositionRelativeToPage) Or _
.Paragraphs.Count > 1 Then
MsgBox "Cell text is on at least two lines, merge!"
Else
MsgBox "Cell text is on one line, no merge!"
End If
Else
MsgBox "Cell is empty, no merge!"
End If
End With
End If
 
Top