Refreshing hyperlinks on backup copies

L33

Board Regular
Joined
Jul 2, 2008
Messages
108
Hi,

I have a workbook with hyperlinks to several other workbooks that are stored in a number of different folders. I want to be able to copy the whole root folder in which they are all contained on to a shared drive, but maintain the hyperlink structure. Although I'm maintaining the folder hierarchy, the hyperlinks still point at the original versions of the folders on my C: drive.

Does anyone have a macro that I can run on the master workbook that'll go looking for the other files and update the links?


Thanks!
 

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.

nirvana_

Board Regular
Joined
Mar 25, 2009
Messages
141
Make sure you have a backup of your files before trying this. Just a few things to remember.

1) In this case the file is assumed to be stored locally in "C:\temp\"

Hence I have used Left(h.address,8) which mean "C:\temp\" is 8 chars in length.

If for example you use the local address as "C:\My Temp\" you will have to re-modify the statement to Left(h.address,11) since "C:\My Temp\" is 11 chars in length.

2) The new mid statement will 8+1 in case of "c:\temp\" which means.
h.Address = NewLocation & Mid(h.Address, 9, Len(h.Address))

The new mid statement will 11+1 in case of "c:\temp\" which means.
h.Address = NewLocation & Mid(h.Address, 12, Len(h.Address))

3) This code only changes the hyperlinks not the display actual names within the excel sheet.

You will need to modify this code according to your needs.

Hope this makes sense.

Code:
Sub UpdateHyperlinks()
    Dim NewLocation As String
    NewLocation = "Z:\NewLocation\"
    For Each h In Worksheets(1).Hyperlinks
        If Left(h.Address, 8) = "c:\temp\" Then
            h.Address = NewLocation & Mid(h.Address, 9, Len(h.Address))
        End If
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,196,027
Messages
6,012,950
Members
441,740
Latest member
abaz21

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
Top