tic
tic

Reputation: 4189

MS Word: select text inside a table cell

I need to select a text (for example, two chars) inside a cell in a table in a Word document. The following code:

Sub testTable()
For Each itable In ActiveDocument.Tables
       itable.Cell(1, 2).Range.Select 
Next
End Sub

selects all the content of the second cell in the first row of the table. How have I to modify it to select only a subset of the cell content, for example from the 4th char to the 9th char?

Upvotes: 3

Views: 16157

Answers (1)

Cindy Meister
Cindy Meister

Reputation: 25663

The Range object has a Characters property, so:

itable.Cell(1,2).Range.Characters(4).Select
Selection.MoveEnd wdCharacter, 5

Another way to go about it is to work with Range objects:

Dim rng as Word.Range
Set rng = itable.Cell(1,2).Range.Characters(4)
rng.End = itable.Cell(1,2).Range.Characters(9)

And there are variations on the theme...

Upvotes: 3

Related Questions