Selecting file and returing/copying the filepath into a Cell

DEE_715

New Member
Joined
Feb 12, 2014
Messages
10
Hi Guy's,

First up I want to apologise, I know this is probably very simple but I haven't worked with VBA in quite a while.
I appreciate any help you can provide in advance.

Basically I want to select an excel file from explorer and then return the full file path into a cell in my current excel workbook i.e. A1.
I'm using the below code which allows me to search/select the file but I'm stumped on how to get it to return the full file path into A1.

Many Thanks
David


Sub browseFilePath()
On Error GoTo err
Dim fileExplorer As FileDialog
Set fileExplorer = Application.FileDialog(msoFileDialogFilePicker)


fileExplorer.AllowMultiSelect = False

With fileExplorer
If .Show = -1 Then
[filePath] = .SelectedItems.Item(1)
Else
MsgBox "You have cancelled the dialogue"
[filePath] = ""
End If
End With
err:
Exit Sub
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
How about
VBA Code:
With fileExplorer
   If .Show = -1 Then
      Range("A1") = .SelectedItems.Item(1)
   Else
      MsgBox "You have cancelled the dialogue"
   End If
End With
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,935
Members
449,094
Latest member
teemeren

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