简体   繁体   中英

Excel VBA for linking Hyperlink formula in a cell to a Macro

I Have a long list of hyperlink formulas in column B. Below is an example of the formula inside a cell. What i want to achieve is when i click a hyperlink in any rows of the whole column B, It will run also a separate single VBA Macro.

=HYPERLINK("#SHEET1!D"&ROW(D2066),D2066)

Thank you.

There is a Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink) event but I don't think it will work with a hyperlink formula. Possibly a selection_change event would work in this case.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
    If Target.Column = 2 Then
        If Left(Target.Formula, 10) = "=HYPERLINK" Then
            MsgBox "My Code here"
        End If
    End If
End Sub

This would go in the worksheet module.


在此处输入图片说明

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