I have a macro that updates hyperlinks in a spreadsheet:
Sub Fix192Hyperlinks()
Dim OldStr As String, NewStr As String
OldStr = "old text"
NewStr = "new text"
Dim hyp As Hyperlink
For Each hyp In ActiveSheet.Hyperlinks
hyp.Address = Replace(hyp.Address, OldStr, NewStr)
Next hyp
End Sub</SPAN>
This has worked very well for me until a new problem arose. If the "old text" appears more than once in the hyperlink, once as a folder name and once as a file name, then the macro replaces too much of the link and it doesn't work. Is there a way modify the macro to replace the "old text" string only the first time it appears and not any subsequent times?
Thanks so much for your help!
Sub Fix192Hyperlinks()
Dim OldStr As String, NewStr As String
OldStr = "old text"
NewStr = "new text"
Dim hyp As Hyperlink
For Each hyp In ActiveSheet.Hyperlinks
hyp.Address = Replace(hyp.Address, OldStr, NewStr)
Next hyp
End Sub</SPAN>
This has worked very well for me until a new problem arose. If the "old text" appears more than once in the hyperlink, once as a folder name and once as a file name, then the macro replaces too much of the link and it doesn't work. Is there a way modify the macro to replace the "old text" string only the first time it appears and not any subsequent times?
Thanks so much for your help!