在单独的选项卡中打开VBA中的多个超链接

时间:2015-09-29 18:49:08

标签: excel-vba excel-2013 vba excel

我已经为这个问题找到了许多不同的解决方案,但这是我迄今为止找到的最好的代码:

Sub OpenHyperLinks()
    Dim xHyperlink As Hyperlink
    Dim WorkRng As Range
    On Error Resume Next
    xTitleId = "KutoolsforExcel"
    Set WorkRng = Application.Selection
    Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
    For Each xHyperlink In WorkRng.Hyperlinks
        xHyperlink.Follow
    Next
End Sub

问题是这会打开同一选项卡中的所有超链接,因此我只会加载最后一页。我想要的是在单独的选项卡中显示的所有链接。我如何修改它以获得我正在寻找的东西?

1 个答案:

答案 0 :(得分:0)

Welp,我终于找到了一个更好的解决方案:只需使用Wscript。

Sub OpenDemLinksBoi()
    Dim SelecRng As Range

    Set SelecRng = Application.Selection
    Set SelecRng = Application.InputBox("Range", SelecRng, Type:=8)

    For Each Cell In SelecRng
    Set objShell = CreateObject("Wscript.Shell") 'I think this basically allows you to input shell commands, hence the "Run" in the next line, which functions exactly like Run. Test it out, try putting a link_
    'into Run and see what happens. Same thing as this script.
    objShell.Run (Cell)
    Next

End Sub