在Excel单元格中创建超链接?

时间:2021-12-09 20:24:39

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?

是否可以在一个Excel单元格中创建一个超链接,该超链接只使用可单击链接的单元格文本的一部分?例如,下面的表格模型是否代表了可以在excel2010中轻松构建的东西?

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

模拟了http://dl.dropbox.com/u/14119404/misc/microsoft%20excel%20 - % 20 - book1_2012 - 04 - 24 - 47. - 16 - _14 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.
  • (b)web URL。

Thanks

谢谢

4 个解决方案

#1


3  

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

这在Excel中是不可能的。超链接与整个细胞相关联。

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.

如果您查看Excel超链接对象的文档,您可以看到它与一个范围相关联。如果可以将超链接与单元格中的span关联起来,则超链接对象需要有一个关联的范围和字符对象。

#2


14  

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:

例如:

在Excel单元格中创建超链接?

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

#3


3  

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

#4


0  

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.

上面的一行非常有用……因为我是新来的,所以我不能评论。这是上面的变体,它取工作表上的每一行并从行上的值构建URL。

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

#1


3  

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

这在Excel中是不可能的。超链接与整个细胞相关联。

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.

如果您查看Excel超链接对象的文档,您可以看到它与一个范围相关联。如果可以将超链接与单元格中的span关联起来,则超链接对象需要有一个关联的范围和字符对象。

#2


14  

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:

例如:

在Excel单元格中创建超链接?

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

#3


3  

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

#4


0  

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.

上面的一行非常有用……因为我是新来的,所以我不能评论。这是上面的变体,它取工作表上的每一行并从行上的值构建URL。

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