1

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

IE \\serverOld\accounts\1234.pdf and \\serverNew\accounts\1234.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 吗?

4

1 回答 1

3

试试这个

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
于 2012-07-11T14:30:37.770 回答