I am using Word XP

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

Thanks very much.

Re: Highlighting Sections by Helmut

Helmut
Tue Aug 03 09:37:39 CDT 2004

Hi Kerry,
in principle like this:
Dim s As Integer
Dim oRng As Range
selection.collapse
Set oRng = Selection.Range
oRng.Start = 0
oRng.End = Selection.Range.Start
s = oRng.Sections.Count ' the section the cursor is in
' so far so good
' either
ActiveDocument.Sections(s).Range.Select
Selection.Range.HighlightColorIndex = wdBlue
' or
ActiveDocument.Sections(s).Range.HighlightColorIndex = wdYellow
---
But then Word invariably crashes!!!
Let us know, what you have discovered.
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98



Re: Highlighting Sections by Kerry

Kerry
Tue Aug 03 10:44:04 CDT 2004

Hi Helmut
Many thanks for the code, however, using your example to
start me off I am finding that all of my sections are
being coloured blue.

Any ideas - many thanks.

Kerry

>-----Original Message-----
>Hi Kerry,
>in principle like this:
>Dim s As Integer
>Dim oRng As Range
>selection.collapse
>Set oRng = Selection.Range
>oRng.Start = 0
>oRng.End = Selection.Range.Start
>s = oRng.Sections.Count ' the section the cursor is in
>' so far so good
>' either
>ActiveDocument.Sections(s).Range.Select
>Selection.Range.HighlightColorIndex = wdBlue
>' or
>ActiveDocument.Sections(s).Range.HighlightColorIndex =
wdYellow
>---
>But then Word invariably crashes!!!
>Let us know, what you have discovered.
>---
>Greetings from Bavaria, Germany
>Helmut Weber, MVP
>"red.sys" & chr(64) & "t-online.de"
>Word XP, Win 98
>
>
>.
>

Re: Highlighting Sections by Kerry

Kerry
Tue Aug 03 10:49:41 CDT 2004

Sincere apologies, I have accidentally removed my section
breaks!! I think it must be nearly home time!!

I need to insert some text at the top of the section but
when I test my command I replace the entire text inthe
section rather than insert extra text - please see code
below:- Many thanks.

Sub IndSecTOC
Dim s As Integer
Dim oRng As Range
Selection.Collapse
Set oRng = Selection.Range
oRng.Start = 0
oRng.End = Selection.Range.Start
s = oRng.Sections.Count
ActiveDocument.Sections(s).Range.Select
Secbk = "toc \h \z \t ""section sub heading,2""
\b ""section" & s
'this bit of code is not correct but what should it be???
Selection.Range.Fields.Add Range:=oRng,
Type:=wdFieldEmpty, Text:=Secbk & """,
PreserveFormatting:=False"
Selection.Fields.Update
end sub

>-----Original Message-----
>Hi Helmut
>Many thanks for the code, however, using your example to
>start me off I am finding that all of my sections are
>being coloured blue.
>
>Any ideas - many thanks.
>
>Kerry
>
>>-----Original Message-----
>>Hi Kerry,
>>in principle like this:
>>Dim s As Integer
>>Dim oRng As Range
>>selection.collapse
>>Set oRng = Selection.Range
>>oRng.Start = 0
>>oRng.End = Selection.Range.Start
>>s = oRng.Sections.Count ' the section the cursor is in
>>' so far so good
>>' either
>>ActiveDocument.Sections(s).Range.Select
>>Selection.Range.HighlightColorIndex = wdBlue
>>' or
>>ActiveDocument.Sections(s).Range.HighlightColorIndex =
>wdYellow
>>---
>>But then Word invariably crashes!!!
>>Let us know, what you have discovered.
>>---
>>Greetings from Bavaria, Germany
>>Helmut Weber, MVP
>>"red.sys" & chr(64) & "t-online.de"
>>Word XP, Win 98
>>
>>
>>.
>>
>.
>

Re: Highlighting Sections by Helmut

Helmut
Wed Aug 04 07:01:49 CDT 2004

Hi Kerry,
just one of many and may be more elegant ways,
to insert a field at the start of the selection:
Option Explicit
Dim oDcm As Document
Dim oRng As Range
---
Sub Test444()
Dim s As Integer ' sections
Set oDcm = ActiveDocument
Selection.Collapse
Set oRng = Selection.Range
oRng.Start = 0
oRng.End = Selection.Range.Start
s = oRng.Sections.Count
ActiveDocument.Sections(s).Range.Select
Selection.Collapse ' !
Selection.Fields.Add _
Range:=Selection.Range, _
Type:=wdFieldEmpty, _
Text:="DOCPROPERTY LastSavedBy "
' or the field of your choice
End Sub
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000