Excel字符串中的Visual Basic GetAddress(超链接)

时间:2014-03-24 16:28:05

标签: excel-vba vba excel

我的Excel中有一个VB,它从粘贴的单元格中提取超链接:

Function GetAddress(HyperlinkCell As Range) As String
If HyperlinkCell.Hyperlinks.Count > 0 Then
GetAddress = Replace(HyperlinkCell.Hyperlinks(1).Address, "mailto:", "NOTHING HERE")
Else
GetAddress = ""
End If
End Function

问题是它在#之后剥离了超链接中的任何内容

http://en.wikipedia.org/wiki/Technical_support#Tier.2FLevel_1_.28T1.2FL1.29

变为

http://en.wikipedia.org/wiki/Technical_support

有关如何请求整个字符串的任何建议吗?

1 个答案:

答案 0 :(得分:0)

怎么样:

Function GetAddress(HyperlinkCell As Range) As String
    If HyperlinkCell.Hyperlinks.Count > 0 Then
        GetAddress = Replace(HyperlinkCell.Hyperlinks(1).Address, "mailto:", "NOTHING HERE")
        GetAddress = GetAddress & "#" & HyperlinkCell.Hyperlinks(1).SubAddress
    Else
        GetAddress = ""
    End If
End Function