Assign macro to text in a cell rather than a control

  • Thread starter Thread starter Mack Neff
  • Start date Start date
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?
 
There's the Worksheet_FollowHyperlink event that is fired when a hyperlink
is clicked.
You can put code there.

NickHK
 
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?
 
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
 
Back
Top