Discussion:
Indenting Text within current cell in table
(too old to reply)
Stephen English
2006-01-30 07:15:27 UTC
Permalink
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
Stefan Blom
2006-01-30 08:47:02 UTC
Permalink
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
Post by 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)
Post by Stephen English
Selection.Tables(1).Cell(CurrentRow, CurrentColumn).Select
Selection.i
Selection.Paragraphs.Indent
End If
End Sub
Stephen English
2006-01-31 04:39:11 UTC
Permalink
Hi Stefan
Thank you - that was a great help
Stephen
Post by Stefan Blom
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
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
Post by 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
Post by Stephen English
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
Post by Stephen English
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)
Post by Stephen English
Selection.Tables(1).Cell(CurrentRow, CurrentColumn).Select
Selection.i
Selection.Paragraphs.Indent
End If
End Sub
Stefan Blom
2006-01-31 08:11:46 UTC
Permalink
You are welcome.
--
Stefan Blom
Microsoft Word MVP
Post by Stephen English
Hi Stefan
Thank you - that was a great help
Stephen
Post by Stefan Blom
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
Post by Stephen English
Post by Stefan Blom
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
Post by 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
Post by Stephen English
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
Post by Stephen English
Post by Stefan Blom
the text
Post by Stephen English
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)
Post by Stephen English
Selection.Tables(1).Cell(CurrentRow, CurrentColumn).Select
Selection.i
Selection.Paragraphs.Indent
End If
End Sub
Loading...