【问题标题】:Find and Replace text and turn into hyperlinks查找和替换文本并变成超链接
【发布时间】:2021-10-19 13:09:33
【问题描述】:

是否可以使用查找和替换功能来查找单词并为其附加超链接?下面是一个仅替换文本的示例,有关如何格式化以使其工作的任何建议。我正在努力让 AMD41 超链接到 example.com。正确的代码应该是什么样的?

Set myRange = ActiveDocument.Content 
myRange.Find.Execute FindText:="AMD41", Forward:=True 
If myRange.Find.Found = True Then myRange.Text = "www.example.com"

提前致谢

【问题讨论】:

标签: vba ms-word userform


【解决方案1】:

试试这个:

Option Explicit

Sub TextFindAndHyperlink()
    Dim SearchRange As Range
    Dim SearchText As String
    Dim WebAddress As String
    
    Set SearchRange = ActiveDocument.Range
    SearchText = "AMD41"
    WebAddress = "http://www.example.com/"

    With SearchRange.Find
        Do While .Execute(SearchText, , True, , , , True) = True
            With SearchRange
                .Hyperlinks.Add SearchRange, WebAddress
            End With
            SearchRange.Collapse wdCollapseEnd
        Loop
    End With
End Sub

【讨论】:

    猜你喜欢
    • 2011-09-19
    • 1970-01-01
    • 1970-01-01
    • 2014-04-15
    • 2013-07-12
    • 1970-01-01
    • 2021-11-03
    • 1970-01-01
    • 2011-10-08
    相关资源
    最近更新 更多