TOC QUESTION

L

LEU

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
 
L

Lene Fredborg

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
 
L

LEU

Thanks Lene. That worked.



Lene Fredborg said:
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
 
Top