我正在寻找一种方法来提取一个Excel单元格的超链接,其中该超链接具有指向同一工作簿中另一工作表的超链接。有办法吗?例如:
Cell A1: "HPI" (with hyperlink to Sheet HPI)
result -> Cell B1: HPI
我找到了这个公式,但它不适用于其他工作表。
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
超链接中的文档使用的.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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句