VBA code to re address multiple Hyper links in a workbook

nigly

New Member
Joined
Mar 13, 2015
Messages
3
Hi, wonder if anyone can help please. I have a workbook that has individual Hyperlinks that open up various drawaings. There are in excess of 10,000 drawings and all links worked fine unitl the company replaced my Laptop and all the previous link addresses lost their correct address path and all have defaulted to my C:\ drive. I have changed the names for business reasons but this is the macro i'm running. Grateful for any help?

Sub FixHyperlinkz()

Dim wks As Worksheet

Dim hl As Hyperlink

Dim sOld As String

Dim sNew As String



Set wks = ActiveSheet

sOld = "c:\Users\shared\Drawing office\"

sNew = "\\Original address\shared\Drawing Office\"

For Each hl In wks.Hyperlinks

hl.Address = Replace(hl.Address, sOld, sNew)

Next hl
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Try

VBA Code:
Sub test()
    Dim hLink As Hyperlink
    Dim wSheet As Worksheet
    Dim path As String
    
    sOld = "c:\Users\shared\Drawing office\"
    sNew = "\\Originaladdress\shared\Drawing Office\"
    
    For Each wSheet In Worksheets
        For Each hLink In wSheet.Hyperlinks
            path = Mid(hLink.Address, Len(sOld) + 1)
            hLink.Address = sNew & path
        Next hLink
    Next
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,591
Members
449,089
Latest member
Motoracer88

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