excel vba execute code from HYPERLINK() formula code example

Example: excel Running VBA from a HYPERLINK()

'Execute VBA code from hyperlink on a worksheet that is the result 
'of the HYPERLINK() worksheet function.

'Insert the following function in a standard code module:


Function HyperlinkClick()

    Set HyperlinkClick = Selection
    
    'Do whatever you like here...
    MsgBox "You clicked on cell " & Selection.Address(0, 0)

End Function


'-------------------------------------------------------------------------------

'Now in a worksheet cell, enter the followin formula:

=HYPERLINK("#HyperlinkClick()", "Text you want to Display")


'Clicking on that hyperlink will run the VBA function above.

'Notice the (#) symbol as the first character of the link_location 
'parameter. This is required for the function to work properly.
'
'
'

Tags:

Vb Example