Create a hyperlink within an Excel cell?

前端 未结 5 1063
余生分开走
余生分开走 2021-01-18 06:48

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 som

相关标签:
5条回答
  • 2021-01-18 07:15

    This isn't possible in Excel. Hyperlinks are associated with entire cells.

    If you look at the documentation for the Excel hyperlink object, you can see that it's associated with a Range. If it were possible to associate hyperlinks with a span within the cell, the Hyperlink object would need to have an associated Range and Characters object.

    0 讨论(0)
  • 2021-01-18 07:16

    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
    
    0 讨论(0)
  • 2021-01-18 07:16

    The above one liner was very helpful... since I'm new, I couldn't comment. So here is my variation of the above that takes each row on a worksheet and builds a URL from a value on the row.

    CHGRow = 3
    Worksheets("Page 1").Select
    Cells(CHGRow, 1).Select
    
    Do Until Application.CountA(ActiveCell.EntireRow) = 0
    
        URLVal = "https://our_url_here?some_parameter=" & Cells(CHGRow, cNumber)
        URLText = Cells(CHGRow, cNumber)
        ActiveSheet.Hyperlinks.Add Anchor:=Cells(CHGRow, cURL), Address:=URLVal, TextToDisplay:=URLText
    
        CHGRow = CHGRow + 1
        Cells(CHGRow, 1).Select
    
    Loop
    
    0 讨论(0)
  • 2021-01-18 07:22

    I'd just make your one row into two rows, merge the cells in the columns you need to have it appear to be a single row and when you get to the cell that needs the hyperlink then you put the words on the top cell and the link in the cell below. It will look fine as a non-techy workaround.

    0 讨论(0)
  • 2021-01-18 07:28

    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
    
    0 讨论(0)
提交回复
热议问题