Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default how to tell which hyperlink was clicked

I've got several hyperlinks in a worksheet, and I would like to run some VBA
code in the FollowHyperlink event of the worksheet. However, I would like
to use a series of "If" statements that test to see which of the several
hyperlinks was clicked, so I can set different lines of code to correspond
to the different links.

How do I test to see which of several different hyperlinks was clicked in a
worksheet.

(Tom or Dave - can you help me with this one too?)

Thanks in advance,

Paul


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default how to tell which hyperlink was clicked

In the followhyperlink event, the event argument Target returns a hyperlink
object reference to the hyperlink that triggered the event.

target.Range.Address would return the address of the cell that contained
the hyperlink

target.address and target.subaddress would return those parts of the
hyperlink.

for testing tryt this

Private Sub FollowHyperlink( target as Hyperlink)

msgbox target.Range.Address & vbnewline _
& target.Address & vbNewLine & target.subAddress

End sub

if the hyperlink is to other pages /ranges, then target.address will
probably be empty.

--
Regards,
Tom Ogilvy

Paul James wrote in message
...
I've got several hyperlinks in a worksheet, and I would like to run some

VBA
code in the FollowHyperlink event of the worksheet. However, I would like
to use a series of "If" statements that test to see which of the several
hyperlinks was clicked, so I can set different lines of code to correspond
to the different links.

How do I test to see which of several different hyperlinks was clicked in

a
worksheet.

(Tom or Dave - can you help me with this one too?)

Thanks in advance,

Paul




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default how to tell which hyperlink was clicked

Great! Thank you (again), Tom.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default how to tell which hyperlink was clicked

I got it to work by tweaking the syntax in the first line:

Private Sub worksheet_FollowHyperlink(ByVal target As Hyperlink)
MsgBox "yes"
MsgBox _
target.Range.Address & vbNewLine _
& target.Address & vbNewLine _
& target.SubAddress

End Sub

Thanks again, Tom.

Paul


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default how to tell which hyperlink was clicked

FYI:

Target.Range.Address returns the address where the hyperlink itself is
located.

Target.SubAddress returns the address of the hyperlink's target
(destination).





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default how to tell which hyperlink was clicked

You should always select an event declaration from the dropdown - that would
have avoided any declaration problems. The computer I was posting from only
has Excel 97 (no followhyperlink event), and I don't have the declarations
of all events memorized - so apologize if that caused you a problem. I am
aware of what the msgbox displays. You said you needed to identify what
hyperlink is firing - so I gave you several things to choose from as an
example.

--
Regards,
Tom Ogivy

Paul James wrote in message
...
I got it to work by tweaking the syntax in the first line:

Private Sub worksheet_FollowHyperlink(ByVal target As Hyperlink)
MsgBox "yes"
MsgBox _
target.Range.Address & vbNewLine _
& target.Address & vbNewLine _
& target.SubAddress

End Sub

Thanks again, Tom.

Paul




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default how to tell which hyperlink was clicked

Tom, please know that I wasn't commenting on my observations for your
benefit. You've enlightened me on a number of occasions in these newsgroups
with your explainations when I had a question, and you're operating at
several levels of understanding beyond me. I just noticed a few things
about the followHyperlink event which, while probably obvious to you, were
revelations to me. I shared those observations with the group for the
benefit of others who may be at my level of understanding.

So, thank you again for showing me how to get it done.

Paul


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clicked NO to save, should have clicked YES Jenn Excel Discussion (Misc queries) 1 March 8th 10 09:04 PM
How do I insert a cell which changes value when clicked on JohnRScott Excel Discussion (Misc queries) 2 March 13th 09 04:31 AM
Clicked on no to save too soon Tom Excel Discussion (Misc queries) 3 January 10th 08 06:42 PM
Insert Data when hyperlink is clicked Chuck N Excel Discussion (Misc queries) 2 September 9th 05 05:12 PM
Is there a way to know when a worksheet has been clicked? John[_35_] Excel Programming 3 July 28th 03 10:05 PM


All times are GMT +1. The time now is 01:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"