Excel: Assign macro to hyperlink?

How to assign a macro to a hyperlink?

+3
source share
1 answer

You can do this using an event Worksheet_FollowHyperlink.

For example, I recorded a macro called Macro1, and the following code will run the macro whenever a hyperlink is clicked

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
        Run ("Macro1")
End Sub

But this is not a very effective solution. My hyperlinks point to the same sheet (by default, on the 1st cell), so when you click on the hyperlink, the first cell on this sheet will be selected automatically.

I have not investigated more about this. you can simply cancel the navigation (I don’t know if this is possible) or set the hyperlink property for the current cell so that the selection remains in the same cell.

+3
source

All Articles