Written by Allen Wyatt (last updated January 1, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365
Kerstine has a worksheet with many, many different hyperlinks in it. She is wondering if there is a way she can replace just a part of each link. For instance, she might like to change any instance of http://www.mysite.com/ to c:/documents/mycopy/. If there is anything additional in the links, then that part should remain. So, for instance, if the original link is http://www.mysite.com/thispage.html, it would be changed to c:/documents/mycopy/thispage.html.
This can be easily done with a macro. The reason is because the hyperlinks can be examined and changed using regular string functions. The following macro provides a simple way to address the issue.
Sub EditHyperlinks() Dim lnkH As Hyperlink Dim sOld As String Dim sNew As String sOld = "https://www.mysite.com" sNew = "c:/documents/mycopy/" For Each lnkH In ActiveSheet.Hyperlinks lnkH.Address = Replace(lnkH.Address, sOld, sNew) lnkH.TextToDisplay = Replace(lnkH.TextToDisplay, sOld, sNew) Next End Sub
This routine steps through all the hyperlinks in the current worksheet and makes modifications, if necessary, to each one. Both the hyperlink and the displayed text are changed, as appropriate. All you need to do is make changes to the sOld and sNew strings to specify what you are searching for and what you want to replace it with.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11081) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Changing Portions of Many Hyperlinks.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 365 applications with VBA programming. Written in clear terms and understandable language, the book includes systematic tutorials and contains both intermediate and advanced content for experienced VB developers. Designed to be comprehensive, the book addresses not just one Office application, but the entire Office suite. Check out Mastering VBA for Microsoft Office 365 today!
If you use UNC paths in your links to external information, those paths may need to be changed at some point. You can ...
Discover MoreNeed to change the various targets of a group of hyperlinks? Getting at the underlying link can seem challenging, but it ...
Discover MoreCopying information from one place to another in a worksheet is easy. Copying hyperlinks may not seem that easy, but you ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2025-02-14 09:54:40
J. Woolley
@Euan Robertson
Yes. But if you wonder, try it and see what happens.
2025-02-13 17:36:19
Euan Robertson
Will this work with embedded links? ie not formula cells
Thanks :)
2022-01-01 10:41:06
J. Woolley
For a related Tip, see
https://excelribbon.tips.net/T009898_Extracting_Hyperlink_Information.html
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 © 2025 Sharon Parq Associates, Inc.
Comments