# Userform file picker to hyperlink



## trick247 (Feb 21, 2022)

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?


----------



## Logit (Feb 22, 2022)

```
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


----------



## trick247 (Feb 22, 2022)

Thank you very much!!


----------



## Logit (Feb 22, 2022)

You are welcome.


----------



## cwhaley1 (Jan 4, 2023)

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.


----------



## Logit (Jan 4, 2023)

I reviewed the code and find that the User is selecting the cell.

Not certain what changes you are seeking.


----------

