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
>>
>>
>>.
>>
>.
>