如何以编程方式编辑Word文档中的所有超链接?
答
Dim doc As Document
Dim link, i
'Loop through all open documents.
For Each doc In Application.Documents
'Loop through all hyperlinks.
For i = 1 To doc.Hyperlinks.Count
'If the hyperlink matches.
If LCase(doc.Hyperlinks(i).Address) = "http://www.yahoo.com/" Then
'Change the links address.
doc.Hyperlinks(i).Address = "http://www.google.com/"
'Change the links display text if desired.
doc.Hyperlinks(i).TextToDisplay = "Changed to Google"
End If
Next
Next
+0
完美工作。谢谢。 – jinsungy 2010-07-29 14:29:29
+0
帮助我,谢谢! – 2012-03-30 05:25:46
+1
这不适用于超链接图像= /你知道如何得到这些图像吗? – 2016-04-17 01:29:46
答
链接这帮助了我极大。用户通过其映射的驱动器打开了包含超链接的Word Docs,而不是通过网络进行漫游。数百个文档将被保存!
我用MID()函数:
Sub FixMyHyperlink()
Dim doc As Document
Dim link, i
'Loop through all open documents.
For Each doc In Application.Documents
'Loop through all hyperlinks.
For i = 1 To doc.Hyperlinks.Count
'If the hyperlink matches.
If LCase(doc.Hyperlinks(i).Address) Like "*partOfHyperlinkHere*" Then
'Change the links address. Used wildcards (*) on either side.
doc.Hyperlinks(i).Address = Mid(doc.Hyperlinks(i).Address, 70,20) '
'Change the links display text if desired.
'doc.Hyperlinks(i).TextToDisplay = "Oatmeal Chocolate Chip Cookies"
End If
Next
Next
End Sub
你想要什么样的编辑做什么呢?你想循环访问每个超链接还是对每个链接进行相同的更改? – 2010-07-28 16:57:28
基本上我想在每个超链接上进行替换。文件服务器名称已更改。 – jinsungy 2010-07-28 17:00:43