Convert hyperlink and bookmarked words to html <a> tag in Word using VBA macros

浪子不回头ぞ 提交于 2019-12-13 11:15:37

问题


I have a word with bookmarked like "click here". How should it be converted to HTML anchor tag using VBA macros

<a href="https://stackoverflow.com/">click here</a>

And then, if a word with bookmarked internal or external, how to convert the text, for e.g., a popup box appears on the word like "t20 CTRL+click to Link"

<a href="t20">Introduction Matthew Davidson</a>

回答1:


Actually, I would like to extract the hyperlinks from text. So I have solved the question with below the code.

Sub HlinkChanger()
Dim oRange As Word.Range
Dim oField As Field
Dim link As Variant
With ActiveDocument
.Range.AutoFormat
For Each oRange In .StoryRanges
For Each oFld In oRange.Fields
If oFld.Type = wdFieldHyperlink Then
For Each link In oFld.Result.Hyperlinks
oFld.Select
Selection.InsertBefore "<a href=""" + link.Address + """>"
Selection.InsertAfter "</a>"
Next link
End If
Next oFld
Set oRange = oRange.NextStoryRange
Next oRange
End With
End Sub

Thank you for support...



来源:https://stackoverflow.com/questions/29600076/convert-hyperlink-and-bookmarked-words-to-html-a-tag-in-word-using-vba-macros

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!