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.
Written by Allen Wyatt (last updated March 21, 2020)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
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:
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.
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!
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 MoreMake a reference to a hyperlink in a formula, and you may be surprised that the reference doesn't return an active ...
Discover MoreCombining workbooks that have cross-links to each other can offer some special challenges. This tip examines how you can ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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!!!
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments