Hyperlink to run code

  • Thread starter Thread starter Martin
  • Start date Start date
M

Martin

Hi,

Is there a way to create a hyperlink to run code?

I want to do this as there are lots of hyperlinks on my sheet and I want to
continue this theme rather than add buttons.

Thank you,

Martin
 
You can use the following worksheet event code:

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
MsgBox (Target.Address)
End Sub

The code goes in the worksheet code area, not a standard module.
 
Hi,

i get a message saying target required. I have this code:


Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
MsgBox (E3.Hide2002)
End Sub

E3 is the cell and as you say I have the code in the worksheet area and
Hide2002 is a macro I have written. Is that written as you would expect?
 
Almost there!

Replace:
MsgBox (E3.Hide2002)
with:
Call Hide2002
 
Sorry, one last question! If I had more than one hyperlink is there a way to
state which hyperlink calls which function? Something like:

if select.cell.E3 then
Call Hide2002
end if
 
Yes:

If your hyperlink is in cell C5, for example, then:

ActiveCell.Address would reveal it:

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
MsgBox (ActiveCell.Address)
End Sub

So if you have many hyperlinks, at least you know which cell got clicked!
 

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

Back
Top