EKet
EKet

Reputation: 7314

Excel: Assign a macro to a hyperlink?

How do I assign a macro to a hyperlink?

Upvotes: 2

Views: 12405

Answers (1)

Shoban
Shoban

Reputation: 23016

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.

Upvotes: 3

Related Questions