VBA to open Excel hyperlink does not work when hyperlink generated with a formula

前端 未结 1 430
情深已故
情深已故 2020-11-29 12:54

There seems to be a bug with Excel hyperlinks which are generated with a formula. I\'m using Excel 2010. I have a spreadsheet with cells containing URLs, and my goal is to

相关标签:
1条回答
  • 2020-11-29 13:05

    I'm wondering if anyone has had a similar problem, and why the formula generated hyperlinks are not working for me.

    Alas, this seems to be painful truth: Excel does not add to Hyperlinks collection formula-generated links - below is the screen from the debugger which is pointed to =HYPERLINK("http://www.google.com/";"Google"):

    Cell Hyperlinks collection

    I'm not sure whether this is a deliberate implementation or a bug, but yes, formula-generated links may NOT be opened using Hyperlinks().Follow method.

    However, if you're going to use keyboard shortcut for links opening, just use the following code - it will automatically convert to clickable link selected cell text and open it:

    Sub Open_Hyperlink()
        Selection.Hyperlinks.Add Anchor:=Selection, Address:=Selection.Formula
        Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
    End Sub
    

    Just assign any shortcut and you're ready to go) Here is the sample: https://www.dropbox.com/s/d4cie7lun22quma/FollowLinks.xlsm

    Hope that's somehow helpful. Good luck!

    0 讨论(0)
提交回复
热议问题