Question : Replace string in Hyperlink Address

Dear Experts:

The ACTIVE Worksheet contains a lot of hyperlinks in which the following string ..\My%20Product\... forms part of the Hyperlink address.
I would like to replace this string 'My%20Product' with just 'MyProduct' wherever it is part of the hyperlink address.

After this operation has been finished I would like to perform the same procedure with the displayed name of the hyperlink.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

Answer : Replace string in Hyperlink Address

Dear Andreas,

Please try with the attached code.

What it does is to loop through all the hyperlinks in the activesheet, and replace the strings you mentioned in 2 attributes:

1. Address - is responsible for the link
2. TextToDisplay - is responsible for the text you see in the sheet.

Function that does the replacement is Replace.

Please note you might just give "%20" as string to change and " " (space) as the replacement to get work done in other parts of the address.

Please also note to make a copy of your worksheet before running any code.

Regards
fakest
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
Dim string_to_change As String, string_replacement As String

string_to_change = "\My%20Products\"
string_replacement = "\My Products\"

Dim hl As Hyperlink
For Each hl In ActiveSheet.Hyperlinks
  hl.Address = Replace(hl.Address, string_to_change, string_replacement)
  hl.TextToDisplay = Replace(hl.TextToDisplay, string_to_change, string_replacement)
Next
Random Solutions  
 
programming4us programming4us