Moving the selection within a table cell. Need help.

J

John Wirt

I am trying to Collapse, Move, Expand, etc. the selection within a cell of a
table.

Almost no matter what I try, the code I've written collapses the current
selection to a point at the beginning of text in the cell and then expands
it unit by unit to the whole table. First the insertion point is expanded to
the first word in the text in the table cell, then to include the first and
second word, then the first three words, then the entire cell (row), and
then the entire table. This is not what I want. I want to collapse the
selection to an insertion point at the end of the text in the cell, then
insert some text, and then select that text.

At the beginning of this sequence, the code has just inserted a new row in
the table, inserted some text in the row, and formatted it. Visually, the
selection at the end of these steps appears to be the entire row (the row
has only one cell) in that the selection area includes the entire cell and
laps over the right margin a little. It looks like a selection of the cell
(or in this case the new row) of the table.

The code that inserts the row hs a range, rngTable5, which equals the entire
table where the row has been inserted active. In addition, the newly
inserted row, which consists of a single cell, is selected.

I've tried the following statements to collapse the current selection (the
row) to the end of the text in the first cell (i.e., in the selected one
celled row):

Selection.Shrink
Selection.Collapse Direction:=wdCollapseEnd
Selection.Collapse Direction:=wdCollapseStart
Selection.Move Unit:=wdCell, Count:=1
Selection.Move Unit:=wdCell, Count:=0
Selection.Move Unit:=wdSentence, Count:=Count=1
Selection.MoveEnd Unit:=wdCell, Count:=-1

And soon. No matter which of these statements I try, when I execute it
stepwise by pressing F8 multiple times, the selection collapses to an
insertion point at the beginning of the current cell, expands to the first
word, expands to the second word, expands to the 3rd word, etc., then
expands to the entire cell, the entire row, and finally the entire table.
I've stopped pressing F* at this point, I presumet the next step would be to
select the whole documents.

Anyway, what statement can I use to move a selection within a table cell to
the end of the text in the cell and insert some text at that point and
reexpand the selection to include that text. To start the cell is selected,
not just the text inside the cell.

Thank you.

John Wirt
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi John,

Starting with a cell in a table selected, the following will insert " New
Text" after the text in that cell and select it. It is not necessary to
select it however as the formatting can be applied to myrange.

Dim myrange As Range
Set myrange = Selection.Cells(1).Range
myrange.End = myrange.End - 1
myrange.Start = myrange.End
myrange.InsertBefore " New Text"
myrange.End = Selection.Cells(1).Range.End - 1
myrange.Select

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
J

Jay Freedman

Hi, John,

I think you need to execute these two statements in sequence to get
where you want to go:

Selection.Collapse Direction:=wdCollapseEnd
Selection.Move Unit:=wdCharacter, Count:=-2

The first statement places the selection to the left of the first
character of the row after the original selection. The second
statement moves it backward through the end-of-row mark and the
end-of-cell mark (you can see these if you turn on nonprinting
characters with the ¶ button).

An alternative is this sequence:

Selection.MoveEnd Unit:=wdCharacter, Count:=-2
Selection.Collapse Direction:=wdCollapseEnd

In this case, the selection's starting point remains at the beginning
of the cell while the end point moves back through the two markers,
and then the selection collapses to the end point.
 
J

John Wirt

Doug,
What is the purpose of moving the end of the range back 1 character? Is this
to change the selection so that it does not include the end of the row? It
then includes only the "cell" or does it include the contents of the cell?
John Wirt


"Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS"
 
H

Helmut Weber

Hi John,
maybe this helps, not regarding different stroyranges:
Sub SelectCell(tx%, rx%, cx%)
' end of cell mark included
ActiveDocument.Tables(tx).Cell(rx, cx).Select
End Sub
Public Sub GotoEndofCell(tx%, rx%, cx%)
' end of cell mark excluded
SelectCell tx, rx, cx
Selection.EndKey
End Sub
Public Sub GotoStartofCell(tx%, rx%, cx%)
SelectCell tx, rx, cx
Selection.HomeKey
End Sub
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT4.0, W98
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi John,

It then just refers to the text in the cell without the end of cell
character.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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