Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Changing Huge Numbers of Hyperlinks.

Changing Huge Numbers of Hyperlinks

Written by Allen Wyatt (last updated March 21, 2020)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


9

Wendy has a single Excel worksheet that contains over 1,200 hyperlinks to TIFF files. (These are hyperlinks, not regular links.) Excel hiccupped and had to shut down, so Emily used the AutoSaved files to recover the previously saved file. Now all the previously working hyperlinks don't work. She had the hyperlinks to the images on a shared network drive, but the AutoSave changed the hyperlinks to reference the C: drive. She wonders if there is an easy way to fix them back to the shared network drive.

At first blush it might seem that you could use Excel's regular Find and Replace feature to find the hard drive designation (as in file://c:) and replace it with a network drive (as in file://shareddrive). The problem is that this approach only addresses part of the problem—it only changes the displayed portion of the hyperlink, not the underlying hyperlink itself. The only way you can get to the hyperlink itself is through the use of a macro.

Assuming that all the hyperlinks that need changing are on the same worksheet, then you can use the following macro:

Sub FixHyperlinks()
    Dim h As Hyperlink
    Dim sOld As String
    Dim sNew As String

    sOld = "c:\" 
    sNew = "S:\Network\"
    For Each h In ActiveSheet.Hyperlinks
        h.Address = Replace(h.Address, sOld, sNew)
    Next h
End Sub

All you need to do is change the values assigned to the sOld and sNew variables.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (8624) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Changing Huge Numbers of Hyperlinks.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Where Is that Name?

Want to easily see the location of named ranges in your worksheet? It's easy; all you need to do is use the familiar Zoom ...

Discover More

Deleting Everything Up to a Character Sequence

Sometimes you have too much information in a cell and you need to "pare down" what is there to get to the info you really ...

Discover More

Associating a Name with a Position

Wouldn't it be great if Word allowed you to have a small pop-up that showed you some information associated with a ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Generating Automatic Links to Audio Files

Need to create links to many filenames on your system? Here are a couple of quick ways to get just the connection you need.

Discover More

References to Hyperlinks aren't Hyperlinks

Make a reference to a hyperlink in a formula, and you may be surprised that the reference doesn't return an active ...

Discover More

Finding Wayward Links

Combining workbooks that have cross-links to each other can offer some special challenges. This tip examines how you can ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 2?

2024-08-22 00:51:14

Hemanth

gives a Run-time error '7':
Out of memory

and the debug pointed to this line

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


2024-08-09 19:36:55

AH

Wow thank you so much for this!! It worked for my spreadsheet.


2024-04-29 13:51:19

Abid Guerrero

Awesome, it worked! Thank you Allen, you rock!


2022-10-15 12:22:39

J. Woolley

For related Tips, see https://excelribbon.tips.net/T011081_Changing_Portions_of_Many_Hyperlinks.html and https://excelribbon.tips.net/T009898_Extracting_Hyperlink_Information.html


2022-10-14 14:27:00

Jill in WA

Hi Allen, Thank you so much for the macro! It worked like a charm.

I had a master file that hyperlinked to a bunch of contracts and related documents on a server. We recently changed servers and I thought I was going to have to manually and individually access the related files. Curiously tried Find and Replace but that didn't handle it. Still curious, I Google searched for options and found your answer. Your macro made my day! All the links are intact again!

Saved your macro to my Personal.xlsb so I can access it easily in the future (hoping I won't need it!). I appreciate your work that made my work easier!


2022-09-20 18:24:19

nouradin nurhussein

one word, brilliant


2021-08-18 13:52:11

Bill Wu

Thank you very much Allen for this handy macro. It has saved me lots of time from manually fixing those hyperlink problems in my excel workbook that were caused by the autosave issue (similar to Emily's).

It works wonderfully!


2020-09-18 05:25:08

Kunlay

Hi There, Greeting from Bhutan,

My Microsoft Excel 2016, hyper link is not functioning as it displays a error message " Your organization's policies are preventing us from completing this action for you. For more info, please contact your help desk".
Please help me sort out his error issue.
Tries every possible way going through options provided in you tube & google searches. but non of the options given could solve the issues i had.
Tried in new excel also but while linking the hyperlink it displays the same error
Please help me out


2020-04-14 12:09:30

Jacob D Davis

LIFESAVER!!!


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.