我有一个包含数千行的电子表格。每行包含一个带有路径的超链接。
该路径无效,但是可以通过将其第一部分替换为正确的值来轻松修复。
Example: current hyperlink: F:\Help\index.html
Needed: P:\SystemHelp\index.html
问题在于标准查找/替换无法“查看”超链接的内容。
这是编写宏的唯一方法还是还有其他方法?
最佳答案
嘿 cnx.org,重新发明替换功能的方法。
Sub FindReplaceHLinks(sFind As String, sReplace As String, _
Optional lStart As Long = 1, Optional lCount As Long = -1)
Dim rCell As Range
Dim hl As Hyperlink
For Each rCell In ActiveSheet.UsedRange.Cells
If rCell.Hyperlinks.Count > 0 Then
For Each hl In rCell.Hyperlinks
hl.Address = Replace(hl.Address, sFind, sReplace, lStart, lCount, vbTextCompare)
Next hl
End If
Next rCell
End Sub
Sub Doit()
FindReplaceHLinks "F:\help\", "F:\SystemHelp\"
End Sub
关于Excel超链接批量更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2805046/