Excel: Assign a macro to a hyperlink?

11,929

You can do it using the Worksheet_FollowHyperlink event.

For example I recorded a macro named Macro1 and the following code will run the macro whenever the 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 points to the same sheet (an by default to the 1st cell) so when ever the hyperlink is clicked the first cell in this sheet will be selected automatically.

I didn't investigate more on this. you can simply cancel the navigation (don't know if possible) or set the hyperlink property to the current cell so that the selection stays in the same cell.

Share:
11,929
EKet
Author by

EKet

Updated on June 28, 2022

Comments

  • EKet
    EKet almost 2 years

    How do I assign a macro to a hyperlink?