Log in

View Full Version : Add Text to a Table's Cell - Table is Inside a Shape



Mavila
02-22-2016, 07:04 PM
I select the shape using:

ActiveDocument.Sections(ActiveDocument.Sections.Count).Footers(wdHeaderFoot erFirstPage).Range.ShapeRange(1).Select

If there's no table, I add one and enter text, etc.

If a table exists already, I can't seem to find a way to add text to cell(1,1), for example.

I've used the following and variations thereof:
Selection.ShapeRange.TextFrame.TextRange.Tables(1).Cell(1, 1).Range = "Text"
Selection.ShapeRange(1).TextFrame.TextRange.Tables(1).Cell(1, 1).Range = "Text" (works on the shape in the header, first one in the section I guess)

I've tried Set objShape = Selection and then:
objShape.TextFrame.TextRange.Tables(1).Cell(1, 1).Range = "Text"

I've tried selection the first paragraph in the shape thinking that would get the cursor into the first cell, but that doesn't seem to work either.

Any ideas?

gmayor
02-23-2016, 01:21 AM
To add text to cell 1

Dim oShape As Shape
Dim oTable As Table
Dim oCell As Range
Set oShape = ActiveDocument.Sections(ActiveDocument.Sections.Count).Footers(wdHeaderFoot erFirstPage).Range.ShapeRange(1)
For Each oTable In oShape.TextFrame.TextRange.Tables
Set oCell = oTable.Cell(1, 1).Range
oCell.End = oCell.End - 1
oCell.Text = "This is cell 1 text"
Exit For
Next oTable