Macro to update hyperlinks, but only one instance of a string

cbk2000

New Member
Joined
Jan 28, 2013
Messages
2
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!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Code:
[COLOR=#333333]hyp.Address = Replace(hyp.Address, OldStr, NewStr, 1, 1)[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,215,378
Messages
6,124,603
Members
449,174
Latest member
ExcelfromGermany

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top