View Single Post
  #2   Report Post  
Posted to microsoft.public.word.tables
StevenM[_2_] StevenM[_2_] is offline
external usenet poster
 
Posts: 169
Default Navigating logical table rows

To: Walter Briscoe,

Sub NavigatingRowsAndColumns()
Dim oTable As Table
Dim row As Long
Dim col As Long
Dim s As String

Set oTable = ActiveDocument.Tables(1)
For row = 1 To oTable.rows.count
For col = 1 To oTable.rows(row).Cells.count
s = oTable.rows(row).Cells(col).Range.Text
s = Left(s, Len(s) - 2)
MsgBox s
Next col
Next row
End Sub

The above will not work if cells in the table have been split or merged.
Also, there are other ways to do this, but the above macro illustrates a
simple method.

As for the rest of your message, I couldn't quite figure out what you
wanted. Perhaps you could try again to state what you're wanting. (Also, you
realize that you are in a Word newgroup and not an Excel newsgroup, yes?)

Steven Craig Miller

"Walter Briscoe" wrote:

I use Word 2003 SP1 on Windows XP Professional SP2.
I am very new to VBA programming and usually produce code by recording a
macro and seeing what is done.

I have a document which consists of one table.
The table consists of "logical" rows.

A "logical" row is either a single physical row as in:
R1C1 R1C2 R1C3 R1C4 ...
or a multiple physical row
R1C1 R1C2 R1C3 R1C4 ...
R2C3 R2C4 ...
R3C3 R3C4 ...

I want to pad some logical rows identified by find.execute as in
R1C1 R1C2 find R1C4 ...
or
R1C1 R1C2 R1C3 R1C4 ...
R2C3 find ...
R3C3 R3C4 ...

with bottom padding as in:
R1C1 R1C2 find R1C4 ...
botm botm botm botm ...
or

R1C1 R1C2 R1C3 R1C4 ...
R2C3 find ...
R3C3 R3C4 ...
botm botm ...

The last row happens to be of the form
R1C1 R1C2 find R1C4 ...
and a found cell can be anywhere in a logical row.

I have struggled without success to identify the relevant physical rows.

Incidentally, I was surprised to find that, at the last cell on the last
row, Selection.MoveRight Unit:=wdCell (which the Tab key maps to) causes
a new empty row to be appended.) I do not find this described in the
help for MoveRight.

I also have not found a key or a function which causes a Selection to be
closed as a mouse click outside the selection would do.

If this is not an appropriate group, I apologise for not kibitzing for
long enough and would value suggestions of a better one.

I would also value pointers to any good tutorials on table navigation.
--
Walter Briscoe