[英]Get explicit sheet hyperlink from cell VBA excel
I am looking for a way to extract the hyperlink of an excel cell with hyperlink to another sheet in the same workbook.我正在寻找一种方法来提取带有超链接到同一工作簿中另一个工作表的 excel 单元格的超链接。 Is there a way to do it?
有没有办法做到这一点? In example:
例如:
Cell A1: "HPI" (with hyperlink to Sheet HPI)
result -> Cell B1: HPI
I found this formula but it's not working with reference to another sheet.我找到了这个公式,但它不能参考另一张纸。
Function GetURL(cell As range, Optional default_value As Variant)
'Lists the Hyperlink Address for a Given Cell
'If cell does not contain a hyperlink, return default_value
If (cell.range("A1").Hyperlinks.Count <> 1) Then
GetURL = default_value
Else
GetURL = cell.range("A1").Hyperlinks(1).Address
End If
End Function
A hyperlink within a document uses the .Subaddress
property , not the .Address
property:文档内的超链接使用的
.Subaddress
财产,不是.Address
属性:
Function GetDestination(Target As Range, Optional default_value As Variant) AS Variant
'Lists the Hyperlink Address or Subaddress for a Given Cell
'If cell does not contain a hyperlink, return default_value
If (Target.Cells(1, 1).Hyperlinks.Count <> 1) Then
GetDestination = default_value
Else
With Target.Cells(1, 1).Hyperlinks(1)
If Len(.Address)>0 Then
GetDestination = .Address
Else
GetDestination = .SubAddress
End If
End With
End If
End Function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.