2012-07-11 44 views
1

我们已经迁移了服务器并使用相同的共享路径传输了这些文件。我的客户已经有一个带有超链接的文字文件,它指向旧的服务器名称。更新Word中超链接的一部分

\\serverOld\accounts\1234.pdf and \\serverNew\accounts\1234.pdf

我发现这个VB脚本低于做了什么,我需要,但它是为Excel不字。

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吗?

+0

谁曾批准上述编辑,请加“字VBA”标签,并删除“VS-宏”的标签吧。谢谢。 – 2012-07-11 14:32:19

回答

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 
+0

非常感谢你。 :) – 2012-07-12 15:37:49