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


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 文件的路径(,我想浏览该列并从该超链接打开文件。我上面的代码给出"对象属性 438 不支持错误"。请帮我同样的忙。

这是我的做法。

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

最新更新