用于从工作表的特定范围打开超链接的Vba代码

时间:2018-01-05 07:18:40

标签: excel vba excel-vba hyperlink

Sheets("A").Select
LastRowA = Sheets("A").Cells(Rows.Count, 
"B").End(xlUp).Row
Range("B2:B" & LastRowA).Select
Sheets("A").Range("B2:B" & LastRowA).Follow Hyperlink

我有一个工作表,其中在B列中有超链接(excel文件的路径),我想浏览该列并从该超链接打开文件。我上面的代码给出了#34;对象属性438不支持错误" .Kindly帮我一样。

1 个答案:

答案 0 :(得分:1)

我将如何做到这一点。

Sub FollowHyperlink()
Dim rng As Range
For each rng in Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
    If rng.Hyperlinks.Count > 0 Then
        ThisWorkbook.FollowHyperlink rng.Hyperlinks(1).Address
    End If
Next
End Sub

基于讨论的编辑代码:

Sub FollowHyperlink()
Dim rng As Range
Dim strAddress As String
For Each rng In Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
    If rng.Hyperlinks.Count > 0 Then
        ThisWorkbook.FollowHyperlink rng.Hyperlinks(1).Address
    ElseIf rng.HasFormula And InStr(rng.Formula, "=HYPERLINK(") > 0 Then
        strAddress = Split(rng.Formula, Chr(34))(1)
        ThisWorkbook.FollowHyperlink strAddress
    End If
Next
End Sub