Add the \h switch to several TOC-fields in active Document

A

andreas

Dear Experts:

I got several TOC-fields in the active/current document.

All the TOC-field codes are missing the \h switch.

How can I add the \h switch to all of these TOC-fields using VBA?

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
 
S

Stefan Blom

Try the following sub:

Sub AddHyperlinksToEntries()
Dim t As Field
Dim toc As TableOfContents

For Each t In ActiveDocument.Fields
If t.Type = wdFieldTOC Then
t.Code.Text = t.Code.Text & " \h"

End If
Next t

'Update just in case...
For Each toc In ActiveDocument.TablesOfContents
toc.Update
Next toc

End Sub
 
A

andreas

Try the following sub:

Sub AddHyperlinksToEntries()
Dim t As Field
Dim toc As TableOfContents

For Each t In ActiveDocument.Fields
If t.Type = wdFieldTOC Then
t.Code.Text = t.Code.Text & " \h"

End If
Next t

'Update just in case...
For Each toc In ActiveDocument.TablesOfContents
toc.Update
Next toc

End Sub

HI Stefan,

sorry for the delay in answering. It works just great. Thank you very
much

Regards, Andreas
 
S

Stefan Blom

I'm glad I could help. :)

Stefan Blom
Microsoft Word MVP



"andreas" wrote in message
HI Stefan,

sorry for the delay in answering. It works just great. Thank you very
much

Regards, Andreas
 

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