简体   繁体   中英

Excel: Assign a macro to a hyperlink?

如何将宏指定给超链接?

You can do it using the Worksheet_FollowHyperlink event.

For example I recorded a macro named Macro1 and the following code will run the macro whenever the hyperlink is clicked

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
        Run ("Macro1")
End Sub

But this is not a very effective solution. My hyperlinks points to the same sheet (an by default to the 1st cell) so when ever the hyperlink is clicked the first cell in this sheet will be selected automatically.

I didn't investigate more on this. you can simply cancel the navigation (don't know if possible) or set the hyperlink property to the current cell so that the selection stays in the same cell.

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