VBA- open up file path explorer and add hyperlink

hissonrr

Board Regular
Joined
Feb 6, 2016
Messages
106
Good day all,

Is it possible to use vba to open up the file path explorer (or a specific file path location), let you select a certain file, then paste that file path into a specific cell.

For example I would click on a button, the file path explorer would pop up and I could search for the specific file I need, select that file, then have it copy/paste the hyperlink into a specific cell?

Any help would be appreciated as i have never really done anything with hyperlinks before.

Thanks,

-R
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try this for files on local drive
- cell can be selected with mouse or entered as a value

put this behind your button
Code:
    Call CreateHyperLink

put in standard module
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
 
Last edited:
Upvote 0
thanks for feedback :beerchug:
 
Last edited:
Upvote 0
Hello.
Dear Yongle,
The hyperlink macro provided above works really well. I need the same macro but for a specific cell, without showing a cell in the input window.
Can you please provide a solution.
Thanks in advance,
Esbi.
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

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