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 / October 2005

Tip: Looking for answers? Try searching our database.

End of column shenanigans

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alex - 08 Oct 2005 11:37 GMT
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.

Signature

Address email to user "response" at domain "alexoren" with suffix "com"

Helmut Weber - 08 Oct 2005 12:17 GMT
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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Alex O. - 08 Oct 2005 19:58 GMT
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.

--
Address email to user "response" at domain "alexoren" with suffix "com"
Helmut Weber - 08 Oct 2005 20:56 GMT
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"

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

 
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.