Indenting Text within current cell in table

S

Stephen English

When a user places the cursor at any point in a cell in a table,
I am trying to select all the text within the cell and then indent it. The
text can have list numbers and list bullets within it.
My code is below but it is indenting the whole row of the table.
I tried recording a macro but I can't get the bit about selecting the text
in the cell from that.
Thanks
Stephen

Sub IndentCellText()
Dim CurrentRow As Integer
Dim CurrentColumn As Integer
If Selection.Information(wdWithInTable) = True Then
CurrentRow = Selection.Information(wdStartOfRangeRowNumber)
CurrentColumn = Selection.Information(wdStartOfRangeColumnNumber)
Selection.Tables(1).Cell(CurrentRow, CurrentColumn).Select
Selection.i
Selection.Paragraphs.Indent
End If
End Sub
 
S

Stefan Blom

Try the following:

Sub IndentTextInCell()
Dim p As Paragraph
If Selection.Cells.Count > 0 Then
For Each p In Selection.Cells(1).Range.Paragraphs
p.Indent
Next p
End If
End Sub

According to Word VBA Help, the Indent method is equivalent to
pressing the Increase Indent button on the Formatting toolbar.

If you want to set a specific indent, you'd have to use the LeftIndent
property instead -- something like this:

Sub IndentTextInCell2()
If Selection.Cells.Count > 0 Then
Selection.Cells(1).Range _
.Paragraphs.Format.LeftIndent = 18 'Indent measured in
'points.
End If
End Sub

Note that setting a left indent for numbered paragraphs may cause a
conflict with the indent settings in the Numbering dialog box; the
latter will then eventually "win".

--
Stefan Blom
Microsoft Word MVP


in message
news:[email protected]...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top