I have a 3 X 3 (say tableA) table in MS word. The (2,2)th cell is a split cell(split into 2X2 table). How can I cycle through all the cells in the tableA.
Dim strCellText As String
Dim uResp As String
Dim Row As Integer
Dim Col As Integer
Dim itable As Table
For Each itable In ThisDocument.Tables
uResp = ""
For Row = 1 To itable.Rows.Count
For Col = 1 To itable.Columns.Count
strCellText = itable.Cell(Row, Col).Range.Text
uResp = uResp & Trim(strCellText)
Next
Next
MsgBox uResp
Next
This program gives a compilation error:
Run time error 5914
The requested member of the collection does not exist
How can I iterate though cells of a tables which has split cells.
Or, split cells into smaller cells. Select the cells that you want to merge. Select Layout > Merge Cells. To unmerge cells, select the cells and select Unmerge Cells.
In the table, click the cell that you want to split. Click the Layout tab. In the Merge group, click Split Cells. In the Split Cells dialog, select the number of columns and rows that you want and then click OK.
As your tables get larger, Word automatically breaks tables so the most information can get on each page. This may mean that a row of your table may start on one page and end on the following page.
If you want to go through all cells in all tables in a MS Word Document, even if the cells are merged, I got the results I wanted. Try this:
Sub CheckingInTheCell
Dim C as Cell
Dim tableCount, Ctr
tableCount = ActiveDocuments.tables.count
for Ctr = 1 to tableCount
For each C in ActiveDocument.Tables(Ctr).Range.cells
.....your validations or whatever you would like to do for the cell content
next C
next Ctr
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With