Gil
Sun Mar 13 21:20:31 CST 2005
Thanks Jay!,
Yours is a complete answer as seemingly always. Thanks. :) :)
:)
Gil
"Jay Freedman" <jay.freedman@verizon.net> wrote in message
news:gvq931970qd2hs0a5658vmkl4ddgp1ic35@4ax.com...
> On Sun, 13 Mar 2005 13:22:05 -0800, "Gil Carter"
> <emr.RemoveThisWord@surewest.net> wrote:
>
>>Hi All,
>>I seem to be wading around ... I am looking for code to move cursor up 2
>>whole cells in a table. That's got to be the easiest thing in the world,
>>yes?
>>
>> Selection.MoveUp Unit:=wdCell , Count:=2, Extend:=wdMove
>>
>>All help is greatfully appreciated. :)
>>Gil
>>
>
> Hi Gil,
>
> You might think that should work, by analogy with other kinds of
> moves. But the Help topic for the MoveUp method specifies which
> constants work, and wdCell isn't one of them:
>
> "Unit Optional Variant. The unit by which to move the selection.
> Can be one of the following WdUnits constants: wdLine, wdParagraph,
> wdWindow or wdScreen."
>
> There are a lot of complications to take into consideration -- what do
> you want to do if the Selection is less than 2 rows from the top of
> the table? What if it's partly in a table and partly outside it? Have
> a look at this code, which handles some but not all possibilities (for
> example, it doesn't explicitly check if the destination cell doesn't
> exist because it was merged with one or more cells above it; that will
> trigger the On Error trap).
>
> Sub MoveUp2Cells()
> Dim oTbl As Table
> Dim nRow As Long, nCol As Long
>
> On Error GoTo Bye
>
> With Selection
> ' make sure selection isn't extended
> If .Type <> wdSelectionIP Then
> .Collapse wdCollapseStart
> End If
>
> ' make sure it's in a table
> If Not .Information(wdWithInTable) Then
> Exit Sub
> End If
>
> Set oTbl = .Tables(1)
> nRow = .Information(wdStartOfRangeRowNumber)
> nCol = .Information(wdStartOfRangeColumnNumber)
>
> ' make sure it can move up 2 rows
> If nRow < 3 Then
> GoTo Bye
> End If
>
> oTbl.Cell(nRow - 2, nCol).Select
> .Collapse wdCollapseStart
> End With
>
> Bye:
> Set oTbl = Nothing
> End Sub
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ:
http://word.mvps.org