View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Rob Bovey Rob Bovey is offline
external usenet poster
 
Posts: 811
Default Running a Macro from a Hyperlink

Hi Shetty,

I have tried the above code. There is a little problem. When clicked
the hyperlink in the sheet, excel follows the link, opens the linked
document and then runs the macro.
Is it possible to stop opening the linked document and only run the
macro?


You can do this by using a dummy hyperlink. This is a hyperlink that
points to the same cell it is located in. When the hyperlink is clicked the
only thing that happens in the Excel user interface is that the cell
containing the hyperlink is selected. However, the Worksheet_FollowHyperlink
event fires and you can do everything you want to do after the hyperlink is
clicked using VBA.

Also is it possible to run the macro by typing the name in a cell (like
=runmacro("hide_sht")
For this I Googled a lot without success.


You could use the Worksheet_Change event to watch a specific cell and
run the macro whose name was entered in that cell each time it changes.
Let's say you wanted to run any macro whose name was entered in cell A1. The
event procedure would look like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
Application.Run Target.Value
End If
End Sub

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"Shetty" wrote in message
oups.com...
Hi Rob,
I have tried the above code. There is a little problem. When clicked
the hyperlink in the sheet, excel follows the link, opens the linked
document and then runs the macro.
Is it possible to stop opening the linked document and only run the
macro?

Also is it possible to run the macro by typing the name in a cell (like
=runmacro("hide_sht")
For this I Googled a lot without success.

Regards,
Shetty.