Reputation: 5555
I have a three worddokuments. The first hast the following structure:
Text
Hyperlink
Text
Hyperlink
I try to accomplish the following marcro: Open document 1, loop throu the hyperlinks. Open the hyperlinked documents and insert the text in the documents where the hyperlink in document 1 is.
What I accomplished yet is
Dim hLink As Hyperlink
Dim doc As Document
'Loop throu all hyperlinks
For Each hLink In ThisDocument.Hyperlinks
'Set objectref to document behind hyperlink
Set doc = Documents.Open(hLink.Address)
'AAAAnd Close it.
doc.Close
Next
My problem is, that I do not know how to put the text of the open document, where the hyperlink is and delete this hyperlink. For further puproses the document 1 has to be flexible so that the user can insert hyperlinks and the functionality of inserting is still working.
I thought of deleting the hyperlink and place a bookmark at the same position, name the bookmark, insert the text and delete the bookmark afterwards, but I do not get the hyperlink replaced by a bookmark. I found the hyperlink.Range.Bookmarks Property but no way to use it for my purposes. Anyone who can help me get this done?
Upvotes: 0
Views: 118
Reputation: 78200
Dim i As Long
For i = ThisDocument.Hyperlinks.Count To 1 Step -1
Dim link As Hyperlink, r As Range, addr As String
Set link = ThisDocument.Hyperlinks(i)
Set r = link.Range
addr = link.Address
link.Delete
r.InsertFile addr
Next
Upvotes: 2