excel - 从单元格 VBA excel 获取显式工作表超链接

标签 excel vba

我正在寻找一种方法来提取 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

最佳答案

文档中的超链接 使用the .Subaddress property ,而不是 .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

关于excel - 从单元格 VBA excel 获取显式工作表超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59858275/

相关文章:

python - Pandas:将特定的 Excel 单元格值读入变量

excel - Excel Slicer 的应用程序定义或对象定义错误

EXCEL 列/范围 A 的平均值 如果列/范围 B 或列/范围 C 等于否

excel - 在Excel中使用 'Match'函数返回一个单元格地址

vba - 输入键模拟单击对复选框不起作用

arrays - 使用字符串数组转储超链接方程以文本形式出现

vba - 打开新网页后如何继续 VBA 代码

sql - Excel 对象的语法。更改数字格式

vba - 以编程方式删除超链接而不应用超链接样式

java - 在生产环境中隐藏第一列