Assign macro to text in a cell rather than a control

M

Mack Neff

Is it possible to assign a macro to a word in a cell - like a hyperlink -
rather than to a control button?
 
N

NickHK

There's the Worksheet_FollowHyperlink event that is fired when a hyperlink
is clicked.
You can put code there.

NickHK
 
M

Mack Neff

OK... this is a start, but I'm really a novice at coding... so far have just
recorded macros and followed a few step-by-step VBA projects. Can you be a
bit more specific?
 
N

NickHK

1 - Select the worksheet you have the hyperlink(s) on.
2 - Right-click the WS tab. select "View Code".
3 - Select "Worksheet" from the top left combo box.
4 - Select "FollowHyperlink" from the top right combo box.

VBA will generate the event signature for you:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
'You put your own code here
End Sub
"Target" gives you info on the hyperlink clicked.

There is also the related Workbook_SheetFollowHyperlink, which you can get
to by a similar process as above, but first double click the "ThisWorkbook"
module under your Project:
Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target
As Hyperlink)

End Sub
With this event, you can react to a hyperlink (Target) on any WS (Sh) in
that workbook.

NickHK
 

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