open all hyperlinks from selected column at once in excel

久未见 提交于 2021-02-15 07:40:46

问题


I want to open all the hyperlinks in a column at once,

code i used is

Sub OpenLinks()
Dim HL As Hyperlink
For Each HL In Selection.Hyperlinks
HL.Follow
Next
End Sub

this macro works fine when i select the cell containing www.google.com but dont work when I select cell next to it and run the macro

i have created the links mentioned in green and red column using the formula from this question https://stackoverflow.com/a/65867184/14713550

edit


回答1:


I think you are looking something below. Follow-up from my previous answer for VBA macro you need to convert all text to a valid URL. Here output from Hyperlink() will not work while direct hyperlink to the cell will work. There is big difference between hyperlink to cell and formula to the cell. So, using some VBA functions you have to concatenate all text to a single string then launch that hyperlink using ActiveSheet.FollowHyperlink or ThisWorkBook.FollowHyperlink method. Give a try on my below sub then let me know your feedback.

Sub OpenMyLink()
Dim strURL As String, fixedURL As String
Dim rng As Range
    
    fixedURL = "https://in.tradingview.com/chart/?symbol=NSE:"

    For Each rng In Selection
        strURL = fixedURL & Replace(Replace(rng, "&", "_", 1, 1), "-", "_", 1, 1) & "1!"
        ThisWorkbook.FollowHyperlink strURL
    Next rng

End Sub


来源:https://stackoverflow.com/questions/65879870/open-all-hyperlinks-from-selected-column-at-once-in-excel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!