How do I make a cell equal to the file directory of a selected file?

DouglasWicker

New Member
Joined
Aug 8, 2017
Messages
38
Hi there,

I am looking for a way to paste the directory of a file into a cell of an open workbook. I need the ability to open file explorer and choose the file to copy the directory from.

Thanks,

D
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi there,

I am looking for a way to paste the directory of a file into a cell of an open workbook. I need the ability to open file explorer and choose the file to copy the directory from.

Thanks,

D

For those that might be interested, this works;

Code:
Function GetFolder() As String
    Dim fldr As FileDialog
    Dim sItem As String
    Set fldr = Application.FileDialog(msoFileDialogFilePicker)
    With fldr
        .Title = "Select a Folder"
        .AllowMultiSelect = False
        .InitialFileName = Application.DefaultFilePath
        If .Show <> -1 Then GoTo NextCode
        sItem = .SelectedItems(1)
    End With
    Sheets("Home").Activate
    Range("L3").Value = sItem
NextCode:
    GetFolder = sItem
    Set fldr = Nothing
End Function
 
Upvote 0

Forum statistics

Threads
1,223,984
Messages
6,175,783
Members
452,669
Latest member
reeseann

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