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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top