Assigning macros to a hyperlink

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
For any hyperlink on any worksheet:

Code:
Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target As Hyperlink)

'Name of procedure to execute below
MyMacro

End Sub

Or, in a specific worksheet:

Code:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)

'Name of procedure to execute below
MyMacro

End Sub

If you don't really want it to follow a hyperlink and just execute the macro you can set the hyperlink as a bookmark and use the same cell that contains the hyperlink as the "target".

Hope this helps.

Gary
 
Upvote 0
Thanks will check it out tomo, at present i am out .........Thanks for help though, but could u tell me how do i make a bookmark ???
 
Upvote 0
1. Right click on the cell that is to contain the hyperlink.
2. Pick hyperlink from the popup menu
3. In the hyperlink dialog box select "Place in this document"
4. Enter the address. Same as cell that contains the link. Can be somewhere else if you like but that may irritate your users.

Gary
 
Upvote 0
I have copied the code but when i run the macro i get an error now which i have high lighted in bold ...If anyone can help me would be great...

Range("C1").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
 
Upvote 0
Your purpose eludes me in attempting to have one hyperlink follow another hyperlink that appears to be the same target but ...

My original sample will not work as written to execute the latest code you have shown. The original code was intended for the "Follow Hyperlink" event. If the procedure ("MyMacro" shown in the original sample) is supposed to follow another hyperlink, it is causing a recursion.

For example:

A hyperlink is activated, the "Follow Hyperlink" event fires and calls a macro that activates another hyperlink which causes the "Follow Hyperlink" event to fire again before it has even finished processing the first hyperlink that triggered it. It results in the two procedures basically doing nothing but calling each other until system resources are exhausted.

You could try disabling events as shown below. If you can provide a concise description of exactly what you are trying to do maybe someone can offer a better solution.

Gary

Code:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)

Application.EnableEvents = False

'Name of procedure to execute below
MyMacro

Application.EnableEvents = True


End Sub
 
Upvote 0
Hey gary thanks for the help but its getting too complicated for me as i am not a programmer so i will solve my query by an easy way i think ....my apologies for the trouble .....thanks for the help and your time
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,712
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top