簡體   English   中英

從單元格 VBA excel 獲取顯式工作表超鏈接

[英]Get explicit sheet hyperlink from cell VBA excel

我正在尋找一種方法來提取帶有超鏈接到同一工作簿中另一個工作表的 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM