Userform file picker to hyperlink

trick247

New Member
Joined
Feb 21, 2022
Messages
4
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello,

I've added a command button to my userform and would like to use that to open a file picker that once any file is selected, appears as a hyperlink in my table.

Can anyone help me with this?
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
VBA Code:
Sub CreateHyperLink()
    Dim fd As Object, fPath As String, fName As String, cel As Range
    Set cel = Application.InputBox("Select a cell", "Add Link to File", , , , , , 8)
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
        .InitialFileName = Environ("USERPROFILE") & "\"     'default folder path - MUST  end with[COLOR=#ff0000] [B]\[/B][/COLOR]
        .AllowMultiSelect = False
        .Title = "Please select a file."
        .Filters.Clear
        If .Show = True Then
            fPath = fd.SelectedItems(1)
            fName = Mid(fPath, InStrRev(fPath, "") + 1, 9999)
        Else
            Exit Sub
        End If
    End With
    cel.Hyperlinks.Add Anchor:=cel, Address:=fPath, TextToDisplay:=fName
End Sub

VBA- open up file path explorer and add hyperlink
 
Upvote 0
Solution
Sorry to drag up a mildly old thread, but this code helped me -- thanks for posting it.

Please may I ask if there is a way to amend the code to bypass the 'Select a Cell' window? I would prefer the user to run the macro, be presented with the file picker window and once file has been chosen, the hyperlink be pasted into a cell I determine (written into the code).

I've spent some time trying to re-work it, but cannot decipher the last instructions in the code.
 
Upvote 0
I reviewed the code and find that the User is selecting the cell.

Not certain what changes you are seeking.
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,693
Members
449,048
Latest member
81jamesacct

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