Mac
Mac

Reputation: 3559

Keep hyperlinks while creating a table of contenst in MSFT Word

I have document which is a collection of daily news articles. The heading of each article points to a hyperlink (where the article came from). Is there a way of assembling the table of contents in a way that it points to the hyperlink of the heading and not to the article itself? Currently it is done manually and it is really tedious, I would really like to automate it and make it easier.

Upvotes: 0

Views: 146

Answers (1)

Fionnuala
Fionnuala

Reputation: 91376

A few notes:

Sub CreateList()
Dim hyp As Hyperlink

For Each hyp In ActiveDocument.Hyperlinks
    s = s & hyp.TextToDisplay
    s = s & vbTab & hyp.Address
    s = s & vbTab & hyp.Range.Information(wdActiveEndPageNumber)
    s = s & vbCrLf
Next
    ''Debug.Print s
    ActiveDocument.Range(Start:=0, End:=0).InsertBefore s
End Sub

A more detailed reply may be possible with more information.

Re Comment

Dim hyp As Hyperlink
Dim r As Range
Dim doc As Document
Dim cont As Document

Set doc = Word.Documents("MyDocument.doc")
Set cont = Word.Documents.Add

Set r = cont.Range(Start:=0, End:=0)

For Each hyp In doc.Hyperlinks
    r.Hyperlinks.Add r, hyp.Address, hyp.SubAddress, hyp.ScreenTip, hyp.TextToDisplay, hyp.Target
    Set r = cont.Range(cont.Content.End - 1)
    r.InsertAfter vbTab & hyp.Range.Information(wdActiveEndPageNumber) & vbCrLf
    Set r = cont.Range(cont.Content.End - 1)
Next

Upvotes: 1

Related Questions