transfer Text from one textbox to another as a Hyperlink.

stirlingmw

Board Regular
Joined
Feb 18, 2013
Messages
75
Afternoon all
I have a Userform where I can select a file using FileDialog. When I select the file and press Open the file does not open, but the address of this file is pasted into textURL. When I then press the command button "Add" this line of text is added to a textbox "txtFile" within another Userform "Master". If text is already present in txtFile the new text is added as a Newline the code I am using for this is:

Code:
With Edit.txtILR
        .Value = .Value & vbCrLf & Me.TxtURL.Value
            End With

How can this text become a hyperlink as opposed to plain text? the text being added includes all of the elements required in a hyperlink (e.g. H:\Downloads\Quiz.xlsm). each line of text will be a different hyperlink.

Thanks
Steve
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try this

In the textbox you can not put a hyperlink, but we can simulate one, after filling the textbox, you can click inside the textbox

Code:
Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    If TextBox1.Value <> "" Then
        If Dir(TextBox1.Value) <> "" Then
            Workbooks.Open TextBox1.Value
        End If
    End If
End Sub
 
Upvote 0
DanteAmor
Thank you for the reply, Your solution works fine if there is only one line of text within the textbox1, however, i have multiple lines of text in each textbox, with each line being a separate file address, also the addresses can be for none Excel files, i.e. PDF, Word, Powerpoint etc.
Regards

Steve
 
Upvote 0
DanteAmor
Thank you for the reply, Your solution works fine if there is only one line of text within the textbox1, however, i have multiple lines of text in each textbox, with each line being a separate file address, also the addresses can be for none Excel files, i.e. PDF, Word, Powerpoint etc.
Regards

Steve


In that case it is better to put each line in a listbox. For that is the listbox control, for a list of texts.

You can click on a line and open any file with the following:
Code:
Private Sub ListBox1_Click()
    If Dir(ListBox1.List(ListBox1.ListIndex)) <> "" Then
       ActiveWorkbook.FollowHyperlink ListBox1.List(ListBox1.ListIndex)
    End If
End Sub

To add a line to the listbox:
Code:
Private Sub CommandButton1_Click()
    ListBox1.AddItem Me.TxtURL.Value
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top