【问题标题】:Change display text of all hyperlinks in document更改文档中所有超链接的显示文本
【发布时间】:2015-02-05 12:04:57
【问题描述】:

我几乎没有视觉基础知识,但我知道这可以通过某种方式完成。 我有一个 144 页的文档,我需要在其中显示 url。 例如:显示“Google”的插入链接现在将显示:“Google (www.google.com)”

此文档中有大约 200 多个链接(最初假设只是电子文档),但现在需要拥有它,以便如果有人手头有打印副本,他们就会知道 URL。我对各种想法持开放态度:(

我的一个想法是按 Alt F9 查看域代码,然后以某种方式进行查找替换并输入某种代码以显示文本和 url 显示?

早些时候,我有一个具有一些视觉基础知识的人试图帮助他发现这个我无法为我运行的东西......是我对如何让它运行缺乏了解吗?

    'Private Declare Function GetTickCount Lib "kernel32" () As Long

    Public Sub GetHyperlinks()
    Dim myDoc As Document
    Dim wombat As Hyperlink
    '    Dim starttime As Long
    Dim CurrentDoc As Document

    Applicationhttp://images.intellitxt.com/ast/adTypes/icon1.png.ScreenUpdating = False
    Set CurrentDoc = ActiveDocument
    Set myDoc = Application.Documents.Add()

'    starttime = GetTickCount
    For Each wombat In CurrentDoc.Hyperlinks
        myDoc.Range.InsertAfter wombat.TextToDisplay & vbTab & wombat.Address & vbCrLf
    Next
'    Debug.Print GetTickCount - starttime

    Application.ScreenUpdating = True
    myDoc.Range.ParagraphFormat.TabStops.Add CentimetersToPoints(7.5), wdAlignTabLeft, wdTabLeaderSpaces 'basic formatting
End Sub

【问题讨论】:

    标签: vba hyperlink ms-word


    【解决方案1】:

    这应该适合你(在 Word 2010 中测试):

    Sub UpdateDocLinks()
        Dim link As Hyperlink
        For Each link In ActiveDocument.Hyperlinks
            link.TextToDisplay = link.TextToDisplay & " (" & link.Address & ")"
        Next link
    End Sub
    

    这会将括号中的 URL 附加到文档中的每个活动超链接:

    Google 变为 Google (http://www.google.com)

    【讨论】:

    • 如果您想更改链接的格式以删除下划线或蓝色,这也是可能的。我使用this answer 作为参考,它有一些很好的信息。
    • 神圣的蝙蝠侠!这个地方太棒了!非常感谢,这让我的夜晚和一周的休息变得更加轻松!!
    • 没问题!乐意效劳。这里有很多来自新用户的低质量问题,很高兴看到像您这样的问题得到了合理的解释并讨论了您已经尝试或考虑过的一些事情。 (顺便说一句,介意投票给我的答案吗?)
    猜你喜欢
    • 1970-01-01
    • 2011-12-07
    • 2020-04-20
    • 1970-01-01
    • 1970-01-01
    • 2017-07-01
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多