Hi Arlette,
Thanks for your quick reply and i used ur code and its working nice once again thanks Arlette.
If you don't mind i need one more small help , below is my question.
I want to extract file name which is avialable in particular folder, suppose in C:\temp\ folder total 3 excel files were there with the name of 2054, 2365, 2145 and that would either xls, xlsx , xlsm whatever it may be. I need this file name 2054, 2365 , 2145 in assigned range.
I used this below code but its asking to select path and dialog box also opening, i dont want to open browse to folder option if i run code automatic all the available file name should come.
Option Explicit
Sub GetFileNames()
Dim xRow As Long
Dim xDirect$, xFname$, InitialFoldr$
InitialFoldr$ = "G:\" '<<< Startup folder to begin searching from
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = Application.DefaultFilePath & "\"
.Title = "Please select a folder to list Files from"
.InitialFileName = InitialFoldr$
.Show
If .SelectedItems.Count <> 0 Then
xDirect$ = .SelectedItems(1) & "\"
xFname$ = Dir(xDirect$, 7)
Do While xFname$ <> ""
ActiveCell.Offset(xRow) = xFname$
xRow = xRow + 1
xFname$ = Dir
Loop
End If
End With
End Sub
Thanks,
Naveed.
Bookmarks