Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a hyperlink within an Excel cell?

Tags:

excel

vba

Is it possible to create a hyperlink within an Excel cell which only uses a section of the cell text for the clickable link? I.E. would the below table mockup represent something that can be easily built in Excel 2010?

a mock up http://dl.dropbox.com/u/14119404/misc/Microsoft%20Excel%20-%20Book1_2012-04-16_14-24-47.jpg

I know that an entire cell can be made into a hyperlink easily, but not a specific part of the cell as far as I know.

By hyperlink I also refer to either

  • (a)another cell or,
  • (b)a web URL.

Thanks

like image 970
llawliet Avatar asked Apr 16 '12 21:04

llawliet


2 Answers

After creating the hyperlink you could format the text in the cell so that only the words of interest are underlined/blue. The hyperlink will still work, but obviously you can still have only one link per cell, and clicking anywhere in the text will trigger the hyperlink.

For example:

enter image description here

Sub Tester()

    Dim rng As Range

    Set rng = ActiveSheet.Range("A1")

    rng.Parent.Hyperlinks.Add Anchor:=rng, Address:="", SubAddress:= _
        "Sheet1!A10", TextToDisplay:="this is long text"

    With rng.Font
        .ColorIndex = xlAutomatic
        .Underline = xlUnderlineStyleNone
    End With

    With rng.Characters(Start:=9, Length:=4).Font
        .Underline = xlUnderlineStyleSingle
        .Color = -4165632
    End With

End Sub
like image 187
Tim Williams Avatar answered Sep 21 '22 21:09

Tim Williams


I needed to link to a filename displayed in a cell, so here is what worked for me:

ActiveSheet.Hyperlinks.Add Anchor:=Cells(row, column), Address:=file.Path, TextToDisplay:=file.Path
like image 37
Dino Avatar answered Sep 18 '22 21:09

Dino