Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cycle through all cells in a word table which is having split cells

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.

like image 829
Vinod Avatar asked Mar 23 '13 09:03

Vinod


People also ask

How do you unsplit a cell in Word?

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.

How do I merge and split cells in Word?

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.

Why does my table keep splitting in Word?

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.


1 Answers

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
like image 53
Lav Zolovan Mehta Avatar answered Oct 06 '22 10:10

Lav Zolovan Mehta