更新Word中超链接的一部分



我们已经迁移了一个服务器,并使用相同的共享路径传输文件。我的客户有一个word文档,其中有指向旧服务器名称的超链接。

即。\serverOldaccounts1234.pdf and \serverNewaccounts1234.pdf

我在下面找到了这个VB脚本,它已经完成了我需要的,但它是为Excel而不是Word。

Sub HyperLinkChange()
   Dim oldtext As String
   Dim newtext As String
   Dim h As Hyperlink
' These can be any text portion of a hyperlink, such as ".com" or ".org".
       oldtext = "\topscan-server" 
       newtext = "\ts-sbs" 
' Check all hyperlinks on active sheet.
       For Each h In ActiveSheet.Hyperlinks
       x = InStr(1, h.Address, oldtext)
       If x > 0 Then
           If h.TextToDisplay = h.Address Then
                h.TextToDisplay = newtext
           End If
           h.Address = Application.WorksheetFunction. _
           Substitute(h.Address, oldtext, newtext)
       End If
       Next
End Sub

请有人帮我编辑此文本以使用Microsoft Word 2010吗?

试试这个

Sub HyperLinkChange()
   Dim oldtext As String, newtext As String
   Dim h As Hyperlink
    oldtext = "\topscan-server"
    newtext = "\ts-sbs"
    For Each h In ActiveDocument.Hyperlinks
       If InStr(1, h.Address, oldtext) Then
           If h.TextToDisplay = h.Address Then
                h.TextToDisplay = newtext
           End If
           h.Address = Replace(h.Address, oldtext, newtext)
       End If
    Next
End Sub

最新更新