How to Extract file name from folder excel vba
Please click for download file
https://drive.google.com/open?id=1HpUj-gBSTERFIj6tdV8FQpIrx6bmqJ_h
Below VBA code
-------------------------------------------------------
Sub myextrfile()
Dim n As Integer
Dim i As Integer
Dim xx As String
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = True
.Title = "PLease Select file"
.Show
n = .SelectedItems.Count
For i = 1 To n
xx = .SelectedItems(i)
Range("A" & i).Value = myExtractfilename(xx)
Next i
End With
End Sub
Function myExtractfilename(xx As Variant) As String
Dim totlen As Integer
totlen = Len(xx)
nm = WorksheetFunction.Substitute(xx, "\", "")
newlen = Len(nm)
diff = totlen - newlen
newtext = WorksheetFunction.Substitute(xx, "\", "@", diff)
sp = WorksheetFunction.Search("@", newtext)
newdiff = totlen - sp
myExtractfilename = Right(xx, newdiff)
End Function
------------------------------------------------------------------------------
Please click for download file
https://drive.google.com/open?id=1HpUj-gBSTERFIj6tdV8FQpIrx6bmqJ_h
Below VBA code
-------------------------------------------------------
Sub myextrfile()
Dim n As Integer
Dim i As Integer
Dim xx As String
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = True
.Title = "PLease Select file"
.Show
n = .SelectedItems.Count
For i = 1 To n
xx = .SelectedItems(i)
Range("A" & i).Value = myExtractfilename(xx)
Next i
End With
End Sub
Function myExtractfilename(xx As Variant) As String
Dim totlen As Integer
totlen = Len(xx)
nm = WorksheetFunction.Substitute(xx, "\", "")
newlen = Len(nm)
diff = totlen - newlen
newtext = WorksheetFunction.Substitute(xx, "\", "@", diff)
sp = WorksheetFunction.Search("@", newtext)
newdiff = totlen - sp
myExtractfilename = Right(xx, newdiff)
End Function
------------------------------------------------------------------------------