Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. 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 Portions of Many Hyperlinks.

Changing Portions of Many Hyperlinks

Written by Allen Wyatt (last updated January 1, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


1

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:

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 (11081) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Excel here: Changing Portions of Many 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

Avoiding the Update Links Message

Word allows you to establish links from one document to another. When you open a document containing these links, you may ...

Discover More

Setting Matrix Column Spacing in the Equation Editor

If you are using matrices in your equations, you may want to adjust the spacing used between columns.

Discover More

Changing the Number of Columns in the Middle of a Document

Need to have multiple columns in a page layout that normally consists of a single column? You can change the column ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Inserting Hyperlinks

Connect your worksheets with other workbooks or with the world of the Internet. The ability to add hyperlinks makes this ...

Discover More

Copying a Hyperlink to Lots of Worksheets

Copying information from one place to another in a worksheet is easy. Copying hyperlinks may not seem that easy, but you ...

Discover More

Updating Links in Copied Files

When you copy workbooks that contain links, you may be at a loss as to how to update those links. There are a couple of ...

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 6 - 0?

2022-01-01 10:41:06

J. Woolley

For a related Tip, see
https://excelribbon.tips.net/T009898_Extracting_Hyperlink_Information.html


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.