我们已迁移服务器并使用相同的共享路径传输文件。我的客户有一个word文档,其中包含超链接,指向较旧的服务器名称。
即。
\\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吗?
答案 0 :(得分: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