CPSRI
asked on
file listing in Excel - VBA Script
Hi,
I need a excel sheet it should make a list of files in one column and the path of the folders in another column, i tried it but i got succeeded to retrieve the files list in the given path, but i need the list of all files(in sub-folders and sub-sub-folders) in the given path. Please help me in doing it.
Thanks in advance.
I need a excel sheet it should make a list of files in one column and the path of the folders in another column, i tried it but i got succeeded to retrieve the files list in the given path, but i need the list of all files(in sub-folders and sub-sub-folders) in the given path. Please help me in doing it.
Thanks in advance.
This is the code I used ------
Private Sub CommandButton1_Click()
Dim sFile As String
Dim i As Long
i = 1
sFile = Dir("F:\DotNetApps2009\*.*") '<=== change to suit
Do While sFile <> ""
Cells(i, "A").Value = sFile
On Error Resume Next
sFile = Dir
On Error GoTo 0
i = i + 1
Loop
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
CPSRI,
Forgot to mention, the code I just posted uses late binding, so there is no need to include a reference to the
Microsoft Scripting Runtime library.
Patrick
Forgot to mention, the code I just posted uses late binding, so there is no need to include a reference to the
Microsoft Scripting Runtime library.
Patrick
ASKER
thanks for your reply Mr. Psychotec, could you please help me in adding reference "Microsoft Script Control", how can i add the reference please?
CPSRI,
To add a reference, in the VB Editor select Tools|References from the menu.
Did you try the code I posted? It requires no reference, and also does not require you to hard-code the folder path...
Patrick
To add a reference, in the VB Editor select Tools|References from the menu.
Did you try the code I posted? It requires no reference, and also does not require you to hard-code the folder path...
Patrick
ASKER
wow, Patrick, amazing, this is what exactly I want, and its very perfect thanks a lot,...thank you so much. I just tried your code, before that I tried with Mr. Psychotec's code and i stucked at adding reference. and then I tried your code its really perfect for me. Thank you.
ASKER
Its really perfect for my requirement.
Also change foldername.
Open in new window