简体   繁体   中英

Running a VBA function by clicking an Excel cell

When a specific cell is clicked, I need to run a function. The function is:

HighlightOnWebsite(url As String, phrase As String)

Basically, this function loads a Web Browser Control, brings up the requested page, and highlights the required phrases. The function works more ore less fine.

What I can't figure out is how to get certain cells to call this function.

Lets say each row has 3 cells which contain the following information:

url of some document | some important phrase | will contain call to function

Now, I need to scan the spreadsheet and in the third column of each row, make a clickable cell which calls a function like HighlightOnWebsite(A1,A2).

Would something like this be possible?

You don't have to scan the worksheet.

Create, in each cell of the third column, a static hyperlink that links to that same cell.
Then have a handler in the worksheet:

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
  If Target.Range.Column = 3 Then
    HighlightOnWebsite Target.Range.Offset(0, -2).Value, Target.Range.Offset(0, -1).Value
  End If
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM