问题
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