VBA Macro in Word: How to manipulate text at a sub address given the link to it?
The document I'm working with is full of internal hyperlinks made by Endnote with something like "#_ENREF_76" as the address. I am trying to write a macro that cycles through all hyperlinks, copies the text at the addres开发者_运维百科s in the link and does stuff with it. Like:
For i = ActiveDocument.Hyperlinks.Count To 1 Step -1
With ActiveDocument.Hyperlinks(i)
myText = .get_The_Text_At_The_Address_In_The_Link
doStuff(myText)
End With
Next i
Is this even possible?
I'm not that familiar with Word, but this would work if your linked bookmarks actually contain the text you want to grab.
Sub Tester()
Dim h As Hyperlink, b As Bookmark
For Each h In ActiveDocument.Hyperlinks
'Debug.Print h.TextToDisplay, h.SubAddress
On Error Resume Next
Set b = ActiveDocument.Bookmarks(h.SubAddress)
On Error GoTo 0
If Not b Is Nothing Then
Debug.Print h.SubAddress & " contains '" & b.Range.Text & "'"
End If
Next h
End Sub
精彩评论