Search code examples
excelexcel-2013vba

Opening multiple hyperlinks in VBA in separate tabs


I've found many different solutions for this issue, but here's the best code I've found so far:

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

The problem is that this opens all of the hyperlinks in the same tab, so that I only get the last page loaded. What I want is all of the links displayed in separate tabs. How can I modify this to get what I'm looking for?


Solution

  • Welp, I finally found a better solution: Just use 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