Code for hyperlink advice

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Morning,
On my worksheet i have many invoices which in column P is there invoice number which is hyperlinked to a folder on my pc.
Today clicking on one of the hyperlinked numbers shows a message Unable to open hyperlink.

When i select edit hyperlink i see in the Address field something like the following.
../../../AppData/AppData/AppData/Roaming/Microsoft/DR%20COPY%20INVOICES/80.pdf

If i delete it & save it as a hyperlink again i now see the following.
DR%20COPY%20INVOICES/80.pdf

This works fine.

This is i have a couple of hundred to do.

Is there some code etc that will just show in the address field the part
DR%20COPY%20INVOICES/80.pdf

In this case the invoice is 80 but apart from that the rest of the cose is the same.

Otherwise im going to be here ages.
I dont see why they are even broken ???

Thanks
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try this. Use Find and Replace (Ctrl + H). Edit one of the other hyperlinks which has the wrong address and copy the part that isn't correct and replace it with the correct part and select Replace All, it shouldn't change your invoice numbers at all.
 
Upvote 0
Try this code

VBA Code:
Sub ChangeHyperlinks()
Dim OStr As String, NStr As String
Dim hyper As Hyperlink

OStr = "Old path" 'Change the path name
NStr = "New path" 'Change to the new path

For Each hyper In ActiveSheet.Hyperlinks
    
    If InStr(1, hyper.Address, "\") > 0 Then
        hyper.Address = Replace(hyper.Address, OldStr, NewStr)
    Else
        hyper.Address = NewStr & "\" & hyper.Address
    End If
    'If you want the text for display to change remove the apostrophe from the next line
    'hyper.TextToDisplay = Replace(hyper.Address, OStr, NStr)

Next hyper

End Sub
 
Upvote 0
Good to read you have a solution. Thank you for letting me know. (y)
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,519
Members
448,968
Latest member
Ajax40

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