End of column shenanigans

A

Alex

Hello,

Here's a problem that got me puzzled

Let's say I have a range.

I find the last character:
last = range.Characters.Last

I do some stuff and then I try to insert something in front of it:
last.InsertBefore("x")

But, if my range exactly encompassed a table, the last character will be at the end of the row and it will fail with the jolly message:
"This is not a valid action for the end of the row".

OK, I'll test for it. At the end of the column I have:
last.Text == "\r\a" (2 characters actually but that's fine).

Problem solved? Not exactly.
The same value is returned if my range encompasses just one cell, and in that case the insertion will succeed.

So, my question is: how do I distinguish between the end of a row and the end of a cell?

Any ideas?


Best wishes,
Alex.
 
H

Helmut Weber

Hi Alex,

the end-of-row mark is in a table,
but not in a cell.

With ActiveDocument.Tables(1)
.Rows(1).Range.Characters.Last.Select
MsgBox Selection.Cells.Count
End With

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Alex O.

Hello Helmut,

Thank you for your reply.
the end-of-row mark is in a table,
but not in a cell.

So, in the presence of nested tables, I just have to check that
for Selection.Range.Characters.last, tables.count > cells.count ?

Best wishes,
Alex.
 
H

Helmut Weber

Hi Alex,

I never used nested tables, and I think with good reason.

Don't understand, what you want to do.

Inserting a character in the last cell of a table,
though the are other, less wierd methods:

Dim r As Range
Set r = ActiveDocument.Tables(1).Range
r.Characters.Last.Previous.InsertBefore "x"

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

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