Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Indenting Text within current cell in table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stephen English - 30 Jan 2006 07:15 GMT
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 - 30 Jan 2006 08:47 GMT
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".

Signature

Stefan Blom
Microsoft Word MVP

> 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
[quoted text clipped - 16 lines]
> End If
> End Sub
Stephen English - 31 Jan 2006 04:39 GMT
Hi Stefan
Thank you - that was a great help
Stephen

> Try the following:
>
[quoted text clipped - 48 lines]
> > End If
> > End Sub
Stefan Blom - 31 Jan 2006 08:11 GMT
You are welcome.

Signature

Stefan Blom
Microsoft Word MVP

> Hi Stefan
> Thank you - that was a great help
[quoted text clipped - 52 lines]
> > > End If
> > > End Sub

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.