Create hyperlink via userform

ldarley

Board Regular
Joined
Apr 10, 2012
Messages
82
Hi all

Not sure what is going on with this, I need my code to add a user selected hyperlink through the dialogue box, into a table on a different worksheet. I don't want to overwrite the current cell value with the screen tip either,

What it is doing, is adding the root part of the hyperlink (with \True on the end) to the correct cell but then the last part of the hyperlink - from desktop\ onward to the current active cell (along with writing the screen tip to that cell).

Can anyone point out what i've got wrong?

Code:
Private Sub CommandButton3_Click()


Dim ws As Worksheet
Dim tbl As ListObject
Dim CurrentRef As String
Dim i As Integer
    
    Set ws = Dossier
    Set tbl = ws.ListObjects("Dossier")
        
        'create hyperlink in userform
        CurrentRef = txtprojectref.Value
        i = Right(CurrentRef, 1)
        ws.Hyperlinks.Add Anchor:=tbl.DataBodyRange(i, 1), Address:=Application.Dialogs(xlDialogInsertHyperlink).Show
   
   
 End Sub
 
Last edited:

sijpie

Well-known Member
Joined
Nov 1, 2008
Messages
3,527
The problem is in the way that you use the Application.Dialog(xldialoginserthyperlink) .
This method will insert the hyperlink and tooltip to the active cell.

If you want to use the ws.Hyperlinks.Add method, then you need to capture the hyperlink in a different way as a string.

What are the hyperlinks? files or web links? or locations in a file?

If they are files then you can use the file picker dialog to get the file name, and then build your hyperlink from that.
 

sijpie

Well-known Member
Joined
Nov 1, 2008
Messages
3,527
As an alternative, you can store the current cell address. Then select the cell that needs the hyperlink. Then only use 'Application.Dialogs(xlDialogInsertHyperlink).Show' . Next restore to the saved cell address
 

Forum statistics

Threads
1,081,989
Messages
5,362,581
Members
400,683
Latest member
LogChief

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top