We help IT Professionals succeed at work.

Word 2007: Using a relative reference to access adjacent cells in a table

Medium Priority
Last Modified: 2013-11-25
I am working with a table in Microsoft Word (2007)
1) Using VBA how can I access cells adjacent to the active cell using relative referencing
2) To add to the question, suppose the active cell to be in a nested table, how would I navigate the table object model to access cells in the parent table, where ever they might be, without resorting to direct referencing (e.g. ActiveDocument.Tables.Cell(2,3) &.etc)

Please see attached example or just follow this link to see an illustration of the question

Please provide a snippet for each cell in the illustration. Thank you!


Watch Question

Top Expert 2012
This macro shows a way of working with the outer table.
Sub NestedTables()
    Dim wrdCellInner As Word.Cell
    Dim wrdCellOuter As Word.Cell
    Dim wrdOuterTable As Word.Table
    Dim wrdRange As Word.Range
    Set wrdRange = Selection.Range
    If wrdRange.Cells.Count Then
        Set wrdCellInner = wrdRange.Cells(1)
        If wrdCellInner.NestingLevel = 2 Then
            wrdRange.Expand wdTable
            wrdRange.Collapse wdCollapseEnd
            Set wrdCellOuter = wrdRange.Cells(1)
            Set wrdOuterTable = wrdRange.Tables(1)
            wrdOuterTable.Rows(wrdCellOuter.RowIndex).Height = CentimetersToPoints(3)
            wrdOuterTable.Rows(wrdCellOuter.RowIndex + 3).Height = CentimetersToPoints(3)
        End If
    End If
End Sub

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Thank you GrahamSkan!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.