批量替换Excel中超链接的VBA代码(执行宏即可)

Sub ReplaceLink()

‘ ReplaceLink Macro’

Dim sTobeReplaced As String
Dim sReplaceWith As String

sTobeReplaced = InputBox(“What link content to be replaced?”, “What link content to be replaced”)
sReplaceWith = InputBox(“What link content to be replaced with?”, “What link content to be replaced with?”)

For Each Ws In Application.Worksheets

For Each h In Ws.Hyperlinks
If InStr(h.Address, sTobeReplaced) <> 0 Then
aLink = Replace(h.Address, sTobeReplaced, sReplaceWith)
h.Address = aLink
End If
Next

Next
End Sub