I am using Word XP

How can I highlight all the text in just the current
section?

Thanks very much.

Re: Highlighting Sections by Gerry

Gerry
Sun Aug 08 00:39:28 CDT 2004

The code posted for this, is WAY too long, and most of it is not needed.
Simply use Word's predefined bookmark "\Section". The following will
highlight the current section. It sets the hghlight color to yellow, but
you could make that any of the color constants.

Sub HighlightSection()
Dim CurSection As Range
Set CurSection = ActiveDocument.Bookmarks("\Section").Range
CurSection.Select
Selection.Range.HighlightColorIndex = wdYellow
Set CurSection = Nothing
End Sub


On Tue, 3 Aug 2004 06:57:54 -0700, Kerry
<anonymous@discussions.microsoft.com> wrote:

> I am using Word XP
>
> How can I highlight all the text in just the current
> section?
>
> Thanks very much.



--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/

Re: Highlighting Sections by Gerry

Gerry
Mon Aug 09 00:24:44 CDT 2004

Performing action on the current section is far more easy than the code in
this thread. All it takes is a single line of code. It does not need all
that other stuff. Use the builtin bookmarks "Section". It always refers
to the current section - the one the selection point is in.

ActiveDocument.Bookmarks("\Section").Range.HighlightColorIndex = wdYellow

It will work fine, as long as the selected text does not go outside of the
current section. If it does, then the code will highlight ALL sections
that the Selection range includes (EVEN IF THE SELECTION DOES INCLUDE ALL
OF THE SECTION). In which case, you may want to do some checking, like
with:

Sub HighlightSection()
Dim aDoc As Document
Dim msg As String
Dim response
Set aDoc = ActiveDocument

If Selection.Range.StoryLength > _
aDoc.Bookmarks("\Section").Range.StoryLength Then
msg = "Your current selection covers more than current " & _
"section. Do you want the entire selection highlighted, " & _
"or just the current section?" & vbCrLf & _
"Select Yes to highlight everything." & vbCrLf & _
"Select No to highlight ONLY the current section. Selection "
& _
"will be collapsed to be at the start of the current
section." & vbCrLf & _
"Select Cancel to exit macro."
response = MsgBox(msg, vbYesNoCancel)
Select Case response
Case vbYes
Selection.Range.HighlightColorIndex = wdYellow
Case vbNo
Selection.Collapse Direction:=wdCollapseEnd
Selection.Range.Start = aDoc.Bookmarks("\Section").Start + 1
ActiveDocument.Bookmarks("\Section").Range. _
HighlightColorIndex = wdYellow
Case vbCancel
Exit Sub
End Select
End If
End Sub

On Tue, 3 Aug 2004 06:57:54 -0700, Kerry
<anonymous@discussions.microsoft.com> wrote:

> I am using Word XP
>
> How can I highlight all the text in just the current
> section?
>
> Thanks very much.



--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/