Hyperlink to code

  • Thread starter Daniel Bonallack
  • Start date
D

Daniel Bonallack

Following on from my last post, what I would really like is
- to have a hyperlink-type text in a cell, so that when you mouse over it,
it becomes a hand icon
- but instead of linking this to a file or webpage, I want it to run a maco.

Is this possible?

Thanks
Daniel
 
M

Mike H

Daniel,


Put some text in a cell (This uses A1) and then
Insert|Hyperlink
for the address put the cell the 'hyperlink is in i.e it goes nowhere a
circular hyperlink.

The add this as a workbook module from which you call your sub

Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target
As Hyperlink)
Mysub
End Sub

and your sub

Sub Mysub()
MsgBox "In mysub"
'do lots of things
End Sub

You can do exactly the same from the worksheet 'follow hyperlink event.

Mike
 
M

Mike H

Danial,

I messed up on the event code you need this to prevent any hyperlink calling
your code

Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target
As Hyperlink)
If Target.Range.Address = "$A$1" Then
Mysub
Exit Sub
End If
End Sub

Mike
 
G

Gord Dibben

Select a cell for the hyperlink.

Insert>Hyperlink>Place in this document.

Point to the sheet and cell you have selected and OK

Right-click on the sheet tab and "View Code".

Paste this event code into the module.

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
macroname
End Sub


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top