我正在使用VBA方法从单元格中提取URL:
Sub ExtractHL()
Dim HL As Hyperlink
For Each HL In ActiveSheet.Hyperlinks
HL.Range.Offset(0, 1).Value = HL.Address
Next
End Sub
这将在#示例之前提取URL中的所有内容: 如果整个URL为https://www.w3.org/TR/html4/sgml/entities.html#h-24.4.1,我的结果将仅显示:https://www.w3.org/TR/html4/sgml/entities.html缺少#h-24.4.1 的人是否有VBA解决方案来提取包括哈希在内的整个URL还有之后的一切?
答案 0 :(得分:0)
我通常创建一个函数。在工作簿模块中,粘贴以下功能:
Function HLink(rng As Range) As String
'extract URL from hyperlink
If rng(1).Hyperlinks.Count Then HLink = rng.Hyperlinks(1).Address
End Function
现在将函数用作公式,如下所示:
PS:来自Rick Rothstein
答案 1 :(得分:0)
我找到了另一个site的答案和解释。 #后面的链接部分被视为子地址,通过包含.SubAddress可以解决问题。
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 & "#" &
cell.range("A1").Hyperlinks(1).SubAddress
End If
End Function
答案 2 :(得分:0)
当我可以预测磅/哈希符号放置的位置时,这对我有用。这是我在网上找到的另一个“ GetURL”功能的迭代。
Select A.Store,C.Item,D.Cost
from A
Inner Join C on A.Store=C.Store and A.Item=C.Item
Inner join D on C.Store=D.Store and C.Item=D.Item
Left join B on A.Store=B.Store and A.Item=B.Item
Where b.store is null;