Rows count in a cell

B

Bad Wolf

Hi, I have tried to solve this problem yesterday evening with no result!

I have to put some phrase in a table cell. Most of them fit in a single row,
but some cannot fit in a single row and then take 2 row.
I need to know when this happen because i have to avoid that other columns
in the table get out of alignment.

I tried to get the number of row that are present in a cell in every way
(cell property, paraghrap property and so on...) with no success.

Can you help me? Even an alternative solution, but I have to know when the
phrase have taken two row instead of one.

Thanks and regards

Marco
 
H

Helmut Weber

Hi,
do you mean how many lines of text are in a cell?
If so, have a look at this one:
Sub Test790()
Dim i As Integer
Dim j As Integer
Dim r As Range
Set r = ActiveDocument.Tables(1).Cell(1, 1).Range
i = r.Information(wdFirstCharacterLineNumber)
r.End = r.End - 1
r.Collapse Direction:=wdCollapseEnd
j = r.Information(wdFirstCharacterLineNumber)
MsgBox j - i + 1 ' !
End Sub
---
You can easily turn it into a funtion,
which returns the lines in a given cell
of a given table etc...
In case you get -1 '!
from Information(wdFirstCharacterLineNumber)
switch views, normal to printview and back or so.
 
B

Bad Wolf

Helmut Weber said:
Hi,
do you mean how many lines of text are in a cell?

Yes, sorry...my english is not so good :)
As a partial excuse I can tell you that the italian version of Word call
"riga" the line of text and the table row. ;-)
If so, have a look at this one:
Sub Test790()
Dim i As Integer
Dim j As Integer
Dim r As Range
Set r = ActiveDocument.Tables(1).Cell(1, 1).Range
i = r.Information(wdFirstCharacterLineNumber)
r.End = r.End - 1
r.Collapse Direction:=wdCollapseEnd
j = r.Information(wdFirstCharacterLineNumber)
MsgBox j - i + 1 ' !
End Sub

Your code worked absolutely fine, many many thanks pal!
I was near the solution as I have already tried the
..Information(wdFirstCharacterLineNumber) but I didn't know the "End"
property and the "Collapse" method!
I have to say that I still don't understand what does the r.end=r.end-1 ,
but if I remove it the code doesn't work.

Thanks again,
Marco
 
H

Helmut Weber

Hi Marco,
if the range includes the end-of-cell mark,
that is without r.End = r.End - 1,
the end of the range is between the cells
(in a way), kind of after the end-of-cell mark,
and after collapsing would be in the next cell,
or at the end-of-row mark.
 

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