View Single Post
  #4   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 Brisoe,

As I understand it, one has only three possibilities.

The first example merely repeats what I sent before.

Sub NavigatingTableViaRows()
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

Sub NavigatingTableViaColumns()
Dim oTable As Table
Dim row As Long
Dim col As Long
Dim s As String
Set oTable = ActiveDocument.Tables(1)
For col = 1 To oTable.Columns.count
For row = 1 To oTable.Columns(col).Cells.count
s = oTable.Columns(col).Cells(row).Range.Text
s = Left(s, Len(s) - 2)
MsgBox s
Next row
Next col
End Sub

Sub NavigatingTableViaCells()
Dim oTable As Table
Dim cell As Long
Dim s As String
Set oTable = ActiveDocument.Tables(1)
For cell = 1 To oTable.Range.Cells.count
s = oTable.Range.Cells(cell).Range.Text
s = Left(s, Len(s) - 2)
MsgBox s
Next cell
End Sub

Steven Craig Miller

"Walter Briscoe" wrote:

In message of Thu,
21 Aug 2008 06:34:00 in microsoft.public.word.tables, StevenM
writes

Thanks, Steven for a really prompt reply.

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


That line generates "Cannot access individual rows in this collection
because the table has vertically merged cells".
I got a similar failure when I nested for each oTable, for each oRow,
and for each oCol

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.


I guess I need a less 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?)


I view this as 2 rows:
R1aC1 R1aC2 R1aC3 R1aC4
R1bC3
R2C1 R2C2 R2C3 R2C4

Word views it as
R1C1 R1C2 R1C3 R1C4
R2C1
R3C1 R3C2 R3C3 R3C4

I do understand I am dealing with Word tables. I reckon I have
vertically split cells which Word views as vertically merged cells. The
difference is on how you get there.

Steven Craig Miller


[snip]
--
Walter Briscoe