Create Hyperlink button

别等时光非礼了梦想. 提交于 2020-07-10 04:28:33

问题


I would like to make a table with a collumn with the posibility to add a hyperlink.

The user should be able to push a button or text saying "Add hyperlink" and the default hyperlink box pops up.

Is this possibel in excel with some sort of macro?

I've tried to record macro and searching through the internet, but can't really find anything similar to my issue. And the record macro doesn't show the code for opening the hyperlink box where the user select what address to link.


回答1:


You can display the dialog with:

If Application.Dialogs(xlDialogInsertHyperlink).Show Then
    'they pressed Ok
End If

This will create a Hyperlink for the active-cell, or a shape. It doesn't return the hyperlink details in any other way, so you'll need to read it from, for example, the cell they are in:

Dim hl As Hyperlink

If Application.Dialogs(xlDialogInsertHyperlink).Show Then
    'they pressed Ok
End If

Set hl = ActiveCell.Hyperlinks(1)

If you don't actually need the hyperlink in the cell then you can remove it afterwards (once you've stored its details that you need):

ActiveCell.Hyperlinks.Delete   'or, more likely,
ActiveCell.Clear

If you simply want to display the dialog, and do nothing else with it, then Ctrl-K or

Application.SendKeys "^k"

or adding the Insert Hyperlink button to the Quick Access Toolbar would do this.



来源:https://stackoverflow.com/questions/18001435/create-hyperlink-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!