....
This was supposed to have set up a range, RunEXE, within which
hyperlinks would run external programs based on the cell contents
(hyperlink label) of the cells containing the hyperlinks. I included
foobar as a hyperlink outside the RunEXE range as a hyperlink that
would NOT run via the event handler.
. . . I'm not sure . . . what you meant by have each point to their
own cell. . . .
....
I mean cell A3 initially contains the text 'winver' (without quotes),
you move to cell A3, run Insert > Hyperlink, link to a Place in This
Document and set the cell reference to A3. So the hyperlink refers to
the cell containing it. Similarly for cells A4:A7.
I used 'points to' instead of 'refers to'. My bad.
It's very interesting , but gave mixed results I found. One of the
hyperlinks worked perfectly with no popup (!), but another in the
Named area gave a VBA run-time error 'file not found'. This line was
highlighted in the debugger :
Shell Target.Range.Text, vbNormalFocus ....
. . . Again , it ran the first hyperlink successfully , but gave
the above run-time error for each after. It also selected and
highlighted in blue the RunEXE area.
Which would indicate that you copied and pasted one hyperlink into a
multiple cell range rather than defining each one separately. When you
copy a cell containing a hyperlink and paste into a multiple cell
range, Excel seems to treat all the hyperlinks in the pasted range as
hyperlinks referring to the entire multiple cell range. The Target
hyperlink parameter in the event handler must always be a singe cell
range for this to work. So you need to create hyperlinks in each cell
separately. Tedious but necessary.
You could make the cell contents for these hyperlinks anything AS LONG
AS each cell's contents is distinct from that of all the other cells.
Then you could use a lookup table with these hyperlink labels in the
first column and the actual hyperlink addresses/references in the
second column, name the table RunTBL, and change the event handler to
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
With Me.Parent.Names
If Not Intersect(Target.Range, _
.Item("RunEXE").RefersToRange) Is Nothing Then _
Shell Application.WorksheetFunction.VLookup( _
Target.Range.Text, .Item("RunTBL").RefersToRange, 2), _
vbNormalFocus
End With
End Sub