【问题标题】:How to find a hyperlink text and replace with embedded text?如何查找超链接文本并替换为嵌入文本?
【发布时间】:2020-07-07 05:07:46
【问题描述】:

我应该如何找到超链接文本并替换为以下示例的嵌入文本?

例如1:

目录

<p><a href="ch1">Introduction</a>. It refers to the corresponding id "ch1"/p>
<p><a href="ch2">Research</a>. It refers to the corresponding id "ch2"</p>
<p><a href="ch3">Results</a>. It refers to the corresponding id "ch3"</p>
<p><a href="ch4">Discussion</a>. It refers to the corresponding id "ch4"</p>
<p><a href="ch5">Conclusion</a>. It refers to the corresponding id "ch5"</p>

例如2:

www.google.com
www.stackoverflow.com

例如3:

引用

*see* <a href="ch1">Chapter. 1</a>. It refers to the id "ch1"
*see* <a href="fig1">Fig. 1</a>. It refers to the id "fig1"
*see* <a href="tab1">Table. 1</a>. It refers to the id "tab1"

上述示例使用 VBA 宏转换为 html &lt;a&gt; 标签。

示例 1 应转换为:

     <a href="ch1">Introduction<a>
     <a href="ch2">Research</a>
     <a href="ch3">Results</a>
     <a href="ch4">Discussion</a>
     <a href="ch5">Conclusion</a>

例如2 应转换为:

   <a href="http://www.google.com">www.google.com</a>
   <a href="www.stackoverflow.com">www.stackoverflow.com</a>

例如2 应转换为:

   <a href="http://www.google.com">www.google.com</a>
   <a href="www.stackoverflow.com">www.stackoverflow.com</a>

【问题讨论】:

标签: vba ms-word


【解决方案1】:

实际上,我想从文本中提取超链接。所以我已经用下面的代码解决了这个问题。

    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

【讨论】:

    猜你喜欢
    • 2011-09-19
    • 1970-01-01
    • 2021-10-19
    • 1970-01-01
    • 2021-10-03
    • 2018-03-22
    • 2017-10-15
    • 2013-09-13
    • 1970-01-01
    相关资源
    最近更新 更多