I am trying to remove the underline words in my TOC. I have the following
macro, but it removes all the underlined words in the hole document. What am
I doing wrong?

With ActiveDocument.TablesOfContents
Selection.Find.ClearFormatting
With Selection.Find
.Font.Underline = wdUnderlineSingle
.Replacement.Font.Underline = wdUnderlineNone
.Execute Replace:=wdReplaceAll
End With
End With

RE: TOC QUESTION by lf

lf
Fri May 16 13:12:00 PDT 2008

Your macro searches the entire document, not only the TOC. The adjusted
version of the macro found below first will only search the first TOC in the
document.

Dim oRange As Range

Set oRange = ActiveDocument.TablesOfContents(1).Range

'Only searh oRange
With oRange.Find
.ClearFormatting
.Font.Underline = wdUnderlineSingle
.Replacement.Font.Underline = wdUnderlineNone
.Execute Replace:=wdReplaceAll
End With

'Clean up
Set oRange = Nothing

---
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"LEU" wrote:

> I am trying to remove the underline words in my TOC. I have the following
> macro, but it removes all the underlined words in the hole document. What am
> I doing wrong?
>
> With ActiveDocument.TablesOfContents
> Selection.Find.ClearFormatting
> With Selection.Find
> .Font.Underline = wdUnderlineSingle
> .Replacement.Font.Underline = wdUnderlineNone
> .Execute Replace:=wdReplaceAll
> End With
> End With
>

RE: TOC QUESTION by LEU

LEU
Fri May 16 13:19:03 PDT 2008

Thanks Lene. That worked.



"Lene Fredborg" wrote:

> Your macro searches the entire document, not only the TOC. The adjusted
> version of the macro found below first will only search the first TOC in the
> document.
>
> Dim oRange As Range
>
> Set oRange = ActiveDocument.TablesOfContents(1).Range
>
> 'Only searh oRange
> With oRange.Find
> .ClearFormatting
> .Font.Underline = wdUnderlineSingle
> .Replacement.Font.Underline = wdUnderlineNone
> .Execute Replace:=wdReplaceAll
> End With
>
> 'Clean up
> Set oRange = Nothing
>
> ---
> Regards
> Lene Fredborg
> DocTools - Denmark
> www.thedoctools.com
> Document automation - add-ins, macros and templates for Microsoft Word
>
>
> "LEU" wrote:
>
> > I am trying to remove the underline words in my TOC. I have the following
> > macro, but it removes all the underlined words in the hole document. What am
> > I doing wrong?
> >
> > With ActiveDocument.TablesOfContents
> > Selection.Find.ClearFormatting
> > With Selection.Find
> > .Font.Underline = wdUnderlineSingle
> > .Replacement.Font.Underline = wdUnderlineNone
> > .Execute Replace:=wdReplaceAll
> > End With
> > End With
> >