Hi Team,
I am looking for a VBA code that would ask to select a file and then give its location path in excel column F.
Thanks,
Liz.![]()
Hi Team,
I am looking for a VBA code that would ask to select a file and then give its location path in excel column F.
Thanks,
Liz.![]()
Last edited by Liz_Biz; 10-03-2014 at 11:47 AM.
This opens a file picker dialog, then writes the path of the selected file into the next empty cell in column F:
Alternatively, instead of browsing for a specific file, you can just pick a folder:![]()
Sub fooFile() Dim stFile As String On Error Resume Next With Application.FileDialog(msoFileDialogFilePicker) .AllowMultiSelect = False .Show stFile = .SelectedItems(1) End With If Not stFile = "False" Then ActiveSheet.Cells(Rows.Count, "F").End(xlUp).Offset(1, 0).Value = Left(stFile, InStrRev(stFile, "\") - 1) End If End Sub
![]()
Sub fooFolder() Dim stFolder As String On Error Resume Next With Application.FileDialog(msoFileDialogFolderPicker) .AllowMultiSelect = False .Show stFolder = .SelectedItems(1) End With If Not stFolder = "False" Then ActiveSheet.Cells(Rows.Count, "F").End(xlUp).Offset(1, 0).Value = stFolder End If End Sub
let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source
If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE
Walking the tightrope between genius and eejit...
Thank you so much Olly for looking into this,
Below code is useful but need some modifications.
1) File dialog could select multiple files by using ctrl.
2) Add data from last available cell , not always 2nd one.
3) Path should contain complete path as "C:\Documents and Settings\Liz\Desktop\ABC.xlsx"
![]()
Sub fooFile() Dim stFile As String On Error Resume Next With Application.FileDialog(msoFileDialogFilePicker) .AllowMultiSelect = False .Show stFile = .SelectedItems(1) End With If Not stFile = "False" Then ActiveSheet.Cells(Rows.Count, "F").End(xlUp).Offset(1, 0).Value = Left(stFile, InStrRev(stFile, "\") - 1) End If End Sub
I don't understand your reply, liz.
1) Are you saying you WANT to allow multiple file selections, and write them all into Column F?
2) I have no idea what you mean. Please explain.
3. Simply change this line:to![]()
ActiveSheet.Cells(Rows.Count, "F").End(xlUp).Offset(1, 0).Value = Left(stFile, InStrRev(stFile, "\") - 1)
![]()
ActiveSheet.Cells(Rows.Count, "F").End(xlUp).Offset(1, 0).Value = stFile
1) Yes. Its correct.
2) Its working by solution of 3rd point.
Last edited by Liz_Biz; 10-03-2014 at 11:19 AM.
Okay, here's a version which allows multiple selections:
![]()
Sub fooFile() Dim i As Integer On Error Resume Next With Application.FileDialog(msoFileDialogFilePicker) .AllowMultiSelect = True .Show If Not .SelectedItems.Count = 0 Then For i = 1 To .SelectedItems.Count ActiveSheet.Cells(Rows.Count, "F").End(xlUp).Offset(1, 0).Value = .SelectedItems(i) Next i End If End With End Sub
Thank you Olly. Your are great guy.
Liz.![]()
Happy to help, thanks for the feedback![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks