Specifying Default Hyperlink Text

by Allen Wyatt
(last updated April 19, 2019)


George often inserts hyperlinks into his worksheets. These hyperlinks are to files of various types that reside on his computer system. When he inserts the hyperlinks, the default hyperlink text that Excel inserts is the full path and file name for the file. George would like this hyperlink text, by default, to consist of only the file name, without the full path.

There is one very easy way to accomplish the desired outcome: Simply move the workbook into the same folder with the files to which you want hyperlinks. When you use the Insert Hyperlink dialog box, the filename—without the path—is then used for the link.

If that isn't feasible, then using the Insert Hyperlink dialog box does result in a full path ending up in both the Address field and Text to Display field of the Insert Hyperlink dialog box. There is no way to change this default behavior; you can only edit the default proposed by Excel. This means that you can, on an individual hyperlink basis, edit the Text to Display field in the Insert Hyperlink dialog box so that it shows just the file name, as desired.

Of course, this involves a lot of editing—hence the impetus for George's query. There are a couple of ways around this. The first is to not rely on the Insert Hyperlink dialog box. Instead, construct a formula that inserts the hyperlink using the HYPERLINK function. Let's say, for example, that you have, in cell C2, a path name to the folder containing your files:


Further, you could have a list of filenames in the range D2:D75, such as this:


You could place a formula such as this in cell E2:

=HYPERLINK($C$2 & D2,D2)

Copy the formula down into the range E3:E75, and you'll have your hyperlinks as you desire.

If you already have a bunch of inserted links in the spreadsheet (for example, in column A), you could use a bit larger formula to extract and display just the filename:


You could then hide the column containing the full-path hyperlinks, so you see only the shortened versions that you want.

If you have many hyperlinks that you want to affect, you can use a macro to remove the path from all the existing hyperlinks.

Sub FixHyperlinkDesc()
    Dim h As Hyperlink
    Dim sRaw As String
    Dim iPos As Integer

    For Each h In ActiveSheet.Hyperlinks
        sRaw = h.TextToDisplay
        iPos = Instr(1, sRaw, "\")
        While (iPos > 0)
            sRaw = Mid(sRaw, iPos + 1, Len(sRaw))
            iPos  = Instr(1, sRaw, "\")
        If sRaw <> h.TextToDisplay Then
            h.TextToDisplay = sRaw
        End If
    Next h
End Sub

The only thing the macro touches is the display text for each hyperlink, and it deletes everything before the final backslash. The macro won't affect anything that may appear as the result of a HYPERLINK function.


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 (13279) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365.

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. ...


Adding Quoted Words to an Index

It is not unusual to need to convert one notation in a document into another entirely different notation. For instance, ...

Discover More

Delaying in a Macro

At times, you may want your macro to pause execution. This tip presents four different ways you can add a delay into your ...

Discover More

Rounding to the Nearest Half Dollar

When working with financial data, it's easy to round values to the nearest dollar. What if you want them rounded to the ...

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)

Hyperlinks No Longer Work in a Workbook

Hyperlinks can be a great timesaver and very convenient. Unless, of course, if they don't work as you expect. This tip ...

Discover More

Generating a Web Page

Want your worksheets to be available to others on the Internet? Excel provides a way you can save your data in HTML ...

Discover More

Get Rid of Web Stuff

When you copy information from a Web page and paste it into a worksheet, you can end up with more than you bargained for. ...

Discover More

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

View most recent newsletter.


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}] 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 four less than 4?

2014-11-04 11:54:00

Bigger Don

@Dennis & @Kim

Here's the easy solution for making InStrRev available on the worksheet. All I did was to make the UDF, pass-through the arguments from the worksheet to the VBA function, assigned the result and voila! a worksheet function mimicking what was previously a VBA-only function.

Function udf_InStrRev(StringCheck As String, _
StringMatch As String, _
Optional Start As Long = -1, _
Optional Compare As VbCompareMethod) As String
udf_InStrRev = InStrRev(StringCheck, StringMatch, Start, Compare)
End Function

2014-11-03 12:44:36

Dennis Costello

There is a somewhat simpler formula, too:


As with the original, the idea here is to figure out how many "" characters there are in the string, and then replace the last one with a non-printing character - hence CHAR(1) - and the find that character in the original string. We're still counting the "" by comparing the length of the original string against one with all the ""s removed, and using that as the "which instance to substitute" value. And then finding the sentinel.

My version of the formula is a little simpler in that instead of using another SUBSTITUTE to replace the leading characters (the result of the LEFT function) with a null string, you can simply use the RIGHT function to select all the characters other than the ones to the left (hence, the length of the original string minus the position of the sentinel).

And I agree with the earlier poster - this would be soooo much easier if we could use InStrRev in a function.

2014-10-13 10:41:17

Kim Carlton

Never mind - I figured it out by looking at additional information on the net. Clever. You would think Excel would provide an easier non-macroish way by exposing the VBA InStrRev function to the spreadsheet interface. Would certainly make life a lot easier.

2014-10-13 10:01:34

Bigger Don

@Willy...I was trying to think of that last week and too busy to look it up. Thanks.

That will fix them after the fact, and en masse. But if we put it in the appropriate event procedure it will do it as each on is entered.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Hyperlinks.Count > 0 Then
Application.EnableEvents = False

Target.Hyperlinks(1).TextToDisplay = _
Mid(Target.Hyperlinks(1).TextToDisplay, InStrRev(Target.Hyperlinks(1).TextToDisplay, "") + 1)
Application.EnableEvents = True
End If
End Sub

2014-10-13 08:46:33

Kim Carlton

I'm confused on what the CHAR(1) is doing for the function. I copied this function into my spreadsheet and it is coming up with a #VALUE! error. An ASCII chart look up reveals a CHAR(1) is equivalent to SOH or Start of Heading. Can someone tell me how that is applied here? The last time I used SOH was about 100 years ago with paper tape and then magnetic tape @ 1600 bpi. Ah - the good ol days...

2014-10-11 10:21:14

Willy Vanhaelen

That works fine if you have only a few hyperlinks but if you have a bunch of them, a macro will be handy.

The one in tip can be drastically shortened though. First of all the While Wend loop is obsolete and maintained only for backwards compatibility. It is now recommended to use the Do ... Loop statement that provides a more structured and flexible way to perform a looping.

But most of all it isn't needed here at all. It searches for the last instance of the backslash but VBA provides a function that does simply that in a single operation: InStrRev.

My 6 line macro does the job of this tip's 17 line one more efficiently of course:

Sub FixHyperlinkDesc()
Dim h As Hyperlink
For Each h In ActiveSheet.Hyperlinks
h.TextToDisplay = Mid(h.TextToDisplay, InStrRev(h.TextToDisplay, "") + 1)
Next h
End Sub

2014-10-11 09:51:35

David George

Unless I'm missing something, there's a much easier way to do this.

Why doesn't George just type the text he wants to appear in the cell, right click, and select "Hyperlink"? The dialog box lets him select the file he wants to link.

I have hundreds of these on my budgeting spreadsheet, and these links point to files all over my system, across several different drives.

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

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.