List All files from Folder and Sub-folders in Excel Workbook

.

In this article, we are going to learn about how to list the files from folders. Here we will also learn how to list files from subfolders as well. By using File System Object, we can get the list of all Files inside a folder. An important thing to note here is that File System Object can list only files inside a folder. That means, there can be two scenarios here:
Scenario 1: User wants to list all files from the parent folder only. In this case, all the sub-folders inside the parent folder will be ignored.
Scenario 2: User wants to list of all files in parent folder and their sub-folders.
Let’s take a look in both the scenarios one by one.

User wants to get the list of All files inside a folder
User wants to get the list of all files inside a folder as well as Sub-folders
Free Download – File Manager in Excel

i) VBA code to List all files within a Folder Only

Copy and Paste the below Code and this will list down the list of all the files inside the folder. This will list down all the files only in the specified folder. If there are other files that are there in some other Sub-folders.



Sub GetFilesInFolder(SourceFolderName As String)

'--- For Example:Folder Name= "D:\Folder Name\"

Dim FSO As Scripting.FileSystemObject
Dim SourceFolder As Scripting.folder, SubFolder As Scripting.folder
Dim FileItem As Scripting.File

    Set FSO = New Scripting.FileSystemObject
    Set SourceFolder = FSO.GetFolder(SourceFolderName)

    '--- This is for displaying, wherever you want can be configured

    r = 14
    For Each FileItem In SourceFolder.Files
        Cells(r, 2).Formula = r - 13
        Cells(r, 3).Formula = FileItem.Name
        Cells(r, 4).Formula = FileItem.Path
        Cells(r, 5).Formula = FileItem.Size
        Cells(r, 6).Formula = FileItem.Type
        Cells(r, 7).Formula = FileItem.DateLastModified
        Cells(r, 8).Formula = "=HYPERLINK(""" & FileItem.Path & """,""" & "Click Here to Open" & """)"

        r = r + 1   ' next row number
    Next FileItem

    Set FileItem = Nothing
    Set SourceFolder = Nothing
    Set FSO = Nothing
End Sub

ii) VBA code to List all files within a Folder and sub-folders as well

Copy and Paste the below Code and this will list down the list of all the files inside the folder as well as sub-folders. If there are other files that are there in some other Sub-folders then it will list down all files from each and Every Folder and Sub-folders.


Sub GetFilesInFolder(SourceFolderName As String, Subfolders As Boolean)

'--- For Example:Folder Name= "D:\Folder Name\" and Flag as Yes or No

Dim FSO As Scripting.FileSystemObject
Dim SourceFolder As Scripting.folder, SubFolder As Scripting.folder
Dim FileItem As Scripting.File
'Dim r As Long
    Set FSO = New Scripting.FileSystemObject
    Set SourceFolder = FSO.GetFolder(SourceFolderName)

    '--- This is for displaying, wherever you want can be configured

    r = 14
    For Each FileItem In SourceFolder.Files
        Cells(r, 2).Formula = r - 13
        Cells(r, 3).Formula = FileItem.Name
        Cells(r, 4).Formula = FileItem.Path
        Cells(r, 5).Formula = FileItem.Size
        Cells(r, 6).Formula = FileItem.Type
        Cells(r, 7).Formula = FileItem.DateLastModified
        Cells(r, 8).Formula = "=HYPERLINK(""" & FileItem.Path & """,""" & "Click Here to Open" & """)"

        r = r + 1   ' next row number
    Next FileItem

    '--- This is the Function to go each and Every Folder and get the Files. This is a Nested-Function Calling.

    If Subfolders = True Then
        For Each SubFolder In SourceFolder.Subfolders
            ListFilesInFolder SubFolder.Path, True
        Next SubFolder
    End If

    Set FileItem = Nothing
    Set SourceFolder = Nothing
    Set FSO = Nothing
End Sub

File Manager using Excel Macro in Excel Workbook

I have created one File Manager using the above Code. It basically fetches the list of Files from Folders and Sub-folders and lists them. It fetches other details of the files as well like File Size, Last modified, the path of the File, Type of the File, and a hyperlink to open the file directly from excel by clicking on that.
It looks something like the below:

Excel File Manager

File Manager in Excel Workbook

Buy a coffee for the author

Adsense

Download FREE Tools and Templates

There are many cool and useful excel tools and templates available to download for free. For most of the tools, you get the entire VBA code base too which you can look into it, play around it, and customize according to your need.

Convert PDF Tables to Excel with VBA | Step-by-Step Guide
Convert PDF Tables to Excel with VBA | Step-by-Step Guide

Convert PDF Tables to Excel with VBA | Step-by-Step Guide How to Convert PDF Tables to Excel Using Excel VBA (Macros) Extracting data from PDF tables into Excel can be tedious, but with Excel VBA (macros), you can automate this process and save time. This guide will...

Dynamic Arrays and Spill Functions in Excel: A Beginner’s Guide
Dynamic Arrays and Spill Functions in Excel: A Beginner’s Guide

In today's tutorial, we'll be diving into the exciting world of dynamic arrays and spill functions in Office 365 Excel. These features have revolutionized the way we work with data, providing a more flexible and efficient way to handle arrays. I am going to explain...

How to Declare a Public Variable in VBA
How to Declare a Public Variable in VBA

While programming in VBA sometimes you need to declare a Public Variable that can store the value throughout the program. Use of Public Variable: Let's say you have 4 different Functions in your VBA Code or Module and you have a variable that may or may not be...

What is Excel Formula?

Excel Formula is one of the best feature in Microsoft Excel, which makes Excel a very very rich application. There are so many useful built-in formulas available in Excel, which makes our work easier in Excel. For all the automated work, Excel Macro is not required. There are so many automated things can be done by using simple formulas in Excel. Formulas are simple text (With a Syntax) which is entered in to the Excel Worksheet Cells. So how computer will recognize whether it is a formula or simple text? Answer is simple.. every formula in Excel starts with Equal Sign (=).

You May Also Like…

167 Comments

  1. selva

    hey buddy i love this app, gives me a quick way of finding the files that i really need.. Keep up the great work

    Reply
    • Vishwamitra Mishra

      Thanks Selva !!

      mail me in detail how you want to search the file @ info@learnexcelmacro.com

      Reply
      • Sudhakar

        Dear Vishwamitra Mishra,

        Excellent work!!!!!!, can you help me to get the pages count of pdf files from the same.

        Thanks and best regards

        Reply
  2. George

    Hi Vish,

    This is really a great tool.

    Reply
    • Vishwamitra Mishra

      Thanks George !!

      Reply
  3. Prateek

    Dear Sir,

    Thanks for this Excel Macro. I need little bit of modification in it. Will you be able to help me on this?

    Reply
  4. Nur

    Dear Vish Bhaia, I have prepared an excel macro, but need your help to do some modification, I already sent an email to info@learnexcelmacro.com on Sun, Jun 24, 2012 at 11:45 PM

    Attached sample .xls also given, please help me…Nur

    Reply
  5. kevin

    How can I modify this to search for file types instead of all files?

    Reply
  6. Rosie Huntley

    Hi Vishwamitra,

    This is an awesome tool. THANKS for posting it. I am wondering if there is an easy way to export the results into another worksheet? We often use the infomation polled from directories for comparison. Any thoughts?

    Thanks again!!!

    Rosie

    Reply
    • Vishwamitra Mishra

      Hi,

      Thanks for the feedback. latest version of this tool will solve your problem.

      Soon in 2 days the latest version of this tool is coming. Which will have following features:

      1. Export in new Worksheet

      2. Export in to a text file.

      3. Option to choose certain types of files with multiple selection available.

      Thanks,

      Vish

      Reply
  7. Kevin

    Fantastic. Thank you.

    Reply
    • Vishwamitra Mishra

      Hi Kevin,

      Now you can download the File manager with the following features from here

      1. Export in new Worksheet
      2. Export in to a text file.
      3. Option to choose certain types of files with multiple selection available.

      Thanks,
      Vish

      Reply
  8. Vinod

    Hi Vishwamitra,

    I have tried to run the "get the list of files in folder" script. But got the Compiler error User defined type not defined for this line "Dim FSO As Scripting.FileSystemObject".

    Please help me with this.

    Thanks

    Reply
    • Vishwamitra Mishra

      Hi Vinod,

      Please Check the reference in your excel.
      1. Open your Workbook
      2. Press ALT + F11
      3. Tools –> References –> Select "Microsoft Scripting Runtime"
      4. If it is not selected then select it
      5. Click OK and your done.

      Reply
      • Vinod

        Thanks Vishwamitra.

        Problem is solved.

        Reply
  9. adam

    When I try to export in excel I recieve an error "error occured while exporting. try again" and it keeps throwing that at me when trying again.

    Reply
  10. Ramkumar

    It s very helpful to me

    it will find the files from ftp?

    Reply
  11. roy whitaker

    can you tell me how to edit the list to select .mda (Access Files only)

    Reply
  12. Deepak

    Thanks a lot for this code. Was searching for this type of code since the last two weeks. Made my life simple. Much much appreciated.

    The only change I would need is to get the date the file was created instead of date modified?????

    Reply
    • Ani

      Go to the VB Script and add new attribute
      like
      Cells(iRow, 7).Formula = FileItem.DateCreated
      Cells(iRow, 8).Formula = FileItem.DateLastModified
      Cells(iRow, 9).Formula = FileItem.DateLastAccessed

      Then add corresponding columns in Excel

      Reply
  13. Michael

    GREAT Utility … just what I was looking for and more …. MANY thanks for giving the whole package with code AND a working Excel file

    Reply
  14. Marco

    Thats a great tool, thanks a lot

    Reply
    • happy.en

      Hi,

      This tool is simply superb!!!!I was looking for this exactly…you are a genuis..Thanks again

      But I have a problem!!!

      This tool is not working for excel 2010…when i sort by last modified date…can i give ur email id..i will mail the exact problem to you

      Reply
  15. Paul

    this is a great macro and lists all file types and having all files hyperlinked is invaluable. How would you go about adding a page count for the files especially PDFs?

    Reply
  16. Anik

    Awesome……really helpful.

    Thanks a lot for this good work.

    Reply
  17. Dimitris

    Hi, Thanks for this useful application, but I have problem when opening the file in excel the Microsoft Visual Basic says:

    "Compile Error: Method or data member not found"

    Any idea?

    Thanks

    Reply
  18. Dimitris

    Sorry I didn't mention where exactly is the problem of the error that says:

    “Compile Error: Method or data member not found”

    The following is marked by the compiler in yellow : Private Sub Workbook_Open()

    The following is marked by the compiler in blue : .ListBoxFileTypes

    I would be grateful if there is any help. Thanks.

    Reply
  19. Mayank

    Hi Vishwa

    I have found your macro very useful. We need your help to get one functionality for searching only those files which have some particular word in their name. This word can be alpha numeric. Because we are having a system of storing the files with a specific alpha numeric code.

    Reply
  20. Amit

    Thanks for macro.

    Reply
  21. Reg

    Using Excel 2007 and when click on buttons nothing happens

    Reply
  22. Ganesh

    Hi Vishwamitra,

    I downloaded the FileManager – VBA macro and it was great support to us find or list files in directories.

    We need to add file types if possible pls let me know how do to.

    Regards / Ganesh

    Reply
  23. Marker

    Is there a way to retrieve the author of the files? I have been searching for a while and can't seem to find an answer.

    Reply
  24. Sudhakar

    Hi Vishwamitra,

    Excellent work!!!!!!, can you help me to get the pages count of pdf files from the same.

    Thanks and best regards

    Reply
  25. Ravidas

    Hi Vishwamitra Mishra.

    Would require to know what files are password protected and what files are not password protected, Please help me this.

    Regards

    Ravi

    Reply
  26. Bags

    Hello,

    This code is excellent but I have one question about it. It's possible to get few path (folders) which I want take from them all files with the DateLastModifid ??

    Regards,

    Bags

    Reply
  27. Benjamin

    Hello Vishwamitra Mishra,

    Thanks a lot for the post and the file.

    I just wonder if I'm doing something wrong. When I select several file types in the Forms.ListBox to find specific extensions to fetch, and click on Fetch all File Details it doesn't work properly. It doesn't fetch any results apart from RTF files. However, if I select Fetch all File details it works perfectly fine.

    Kind regards,

    Benjamín

    Reply
  28. Dr. Doss

    Dear Vish,

    It is a great tool and it solved my 3 years of cluelessness as to how to retrieve my endless files that I have stored over a decade. Excellent work.

    But I have one last problem. While your macros work like a bullet in Windows, "Browse" command really does not work in Ubuntu CALC. As I am working with Ubuntu, Please suggest how your sheet work in calc (Please note that most of the macros written for Microsoft work in Ubuntu).

    Your soulution to this bug will be greatly appreciated.

    Doss VA

    Reply
  29. Zigi

    downloaded and it worked great!

    Reply
  30. som

    Dear vish ,

    This is an amazing work. no words to appericate .

    this has reduced my burden in huge level.

    Thank you so much

    regards

    som

    Reply
  31. John

    You are genius.. You helped me a lot.. Tons of Thanks..!

    Reply
    • Vishwamitra Mishra

      Thanks John 🙂

      Reply
  32. Vilmar Monteiro

    Hi, Vishwamitra

    Thanks for a very usefull code.

    I am a brasilien engineer and I do not know if is my office 2013, but your code do not show anything when I select a file or files types that I know exist in folder. What is happening? Can you get it?

    Then for all files type it works and show all!!!

    This code needs a reference?

    Thanks in advance for your answer, help me, please.

    Vilmar

    Reply
    • Yoghi

      Same problem

      Reply
  33. Ani

    This is a great tool to use. I appreciate your help to everyone.
    Could you please let me know if I need to get the File Creator/Owner how can I get that?

    Reply
      • Ani

        Thanks Vishwa..You are really great and helpful. I downloaded your tool and did some modification based on my requirement. Could you please let me know am I good to share this great tool with my office colleague as they also need to do some data extraction from Fileshare.

        Reply
        • Vishwamitra Mishra

          Thanks Ani for appreciating my effort 🙂 Yes it is a completely FREE tool and you can share with your colleagues 🙂

          Reply
  34. Veera

    Really your tool is quite helpful and I am very thankful to you as it saved plenty of my time. It would have been a great help if we had another column with folder name/ Sub-folder name.

    Reply
    • Vishwamitra Mishra

      Thanks Veera for you feedback. In the next version this will be included. Thanks again.

      Reply
  35. Karunakaran

    Thanks

    Reply
  36. Veera

    Boss,
    Is there any chance on my previous request of having a separate column with folder name/ Sub-folder name.

    Reply
  37. Manoj

    Hi Vishwa

    Thanks for sharing the code!

    But there is something needs to corrected onto this file.
    when we select particular file on search it throws nothing.but works good with all search.

    Please inbox me the correction , urgently needed.

    Reply
  38. vijaya kumar

    can you please help me to get this data from FTP

    Reply
  39. Manan

    Can i find files with particular keyword ?

    Reply
  40. Nadeem

    Thanks very much who have made this sheet. It is very helpfull for me.

    Reply
  41. the_blues

    Thanks, this is the simpliest code for listing file list

    Reply
  42. iqbal

    cool brother its help me lot

    Reply
  43. Sharad

    This is superb, brilliant stuff….Thanks a ton 🙂

    Reply
  44. Teak

    Hi, Im getting the Compile error: Method or data member not found. Can you help. Thank you

    Reply
  45. Bharath

    hi,
    The tool is very useful. Can you help me in providing the code for opening the hyperlink and to search the particular string and if it is present. It should copy and paste in another cell

    Reply
  46. Shivangi

    Very useful… Thank you very much.

    Reply
  47. vikanu

    Hey
    I jst want that i m have tif file after segregating that according to need i.e page is form bill or other.i just want according to information those pages moves to form bill and other folder? Can it b done?

    Reply
  48. Colum

    Great macro, it works fine when using Excel 2007 but I get an error when using Excel 2013 Unexpected Error (32809).

    Thanks

    Reply
  49. Hashim

    Thank you great file

    Reply
  50. Hermj

    Thanks Vishwamitra,
    This is a life saver.

    Reply
  51. satish

    Hi Dear,

    How to add desire file extension in Listfile addin.xlam, kindly let me know this.

    Reply
  52. Chris

    Hi, I wonder whether you may be able to help me please. Could you possibly tell me how I would hard code a file type into the script rather than having a tick box for the user to select?

    Many thanks and kind regards

    Chris

    Reply
  53. Kapil

    Hi Vishwa,

    The Macro works perfectly fine for windows. But I need it on windows. When I tried running it on Mac, its giving erroes.
    Need your help regarding this.
    I am not into scripting. I am into post productions of films.And need to maintain information of the directories.

    Thanks.

    Kapil Limbad

    Reply
    • Kapil

      Hi Vishwa,

      The Macro works perfectly fine for Mac. But I need it on windows. When I tried running it on Mac, its giving erroes.
      Need your help regarding this.
      I am not into scripting. I am into post productions of films.And need to maintain information of the directories.

      Thanks.

      Kapil Limbad

      Reply
  54. Ellen

    Wauw, thanks, this is great!

    Reply
    • Vishwamitra Mishra

      Thanks Ellen !!

      Reply
      • Zoaib zaidi

        Hi Vishwa,

        Awesome macro. But i need a little help in it. i want to list and hyperlink the Folder or Sub folders instead of file type. is there any way of doing it?

        Reply
      • Luis

        Hi I would like to incorporate the search of pics on folders and sub folders using the following macro. As well as file name, date created.

        So far this macro will not search within subfolders.

        Regards

        Sub PhotoCatalog()
        Dim i As Double
        Dim xPhoto As String
        Dim sLocT As String
        Dim sPattern As String

        sLocT = “C:Documents and SettingslcoloradoBureauL2 Lucien L_Allier (2S50)10.9.8 Photos chantier1-06-2015”
        sPattern = sLocT & “*.jpg”
        sVideo = sLocT & “*.avi”

        Application.EnableEvents = False
        Application.ScreenUpdating = False

        Range(“A1”).Select
        ActiveCell.FormulaR1C1 = “Aperçu/Photo”
        Range(“B1”).Select
        ActiveCell.FormulaR1C1 = “Lien”
        Range(“C1”).Select
        ActiveCell.FormulaR1C1 = “Description”
        Range(“A1:C1”).Select
        Range(“D1”).Select
        ActiveCell.FormulaR1C1 = “Avant meulage – Date”
        Range(“E1”).Select
        ActiveCell.FormulaR1C1 = “Après meulage – Date”
        Range(“F1”).Select
        ActiveCell.FormulaR1C1 = “Apres injection – Date no.1”
        Range(“A1:F1”).Select

        With Selection.Font
        .Name = “Calibri”
        .FontStyle = “Bold”
        .Size = 12
        .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlMedium
        .ColorIndex = xlAutomatic
        End With

        i = 1
        ‘On Error GoTo 0
        xPhoto = Dir(sPattern, vbNormal)
        Do While xPhoto “”
        i = i + 1
        Range(“B” & i).Select
        ActiveSheet.Pictures.Insert(sLocT & xPhoto).Select
        With Selection.ShapeRange
        .LockAspectRatio = msoTrue
        .Height = 74#
        .PictureFormat.Brightness = 0.5
        .PictureFormat.Contrast = 0.5
        .PictureFormat.ColorType = msoPictureAutomatic
        End With
        Selection.Cut
        Range(“A” & i).Select
        ActiveSheet.Paste
        Range(“B” & i).Select
        ActiveSheet.Hyperlinks.Add Anchor:=Selection, _
        Address:=sLocT & xPhoto, TextToDisplay:=xPhoto
        xPhoto = Dir
        Loop

        Application.EnableEvents = True
        Application.ScreenUpdating = True
        End Sub

        Reply
  55. J Murali Krishna

    Dude This is just freaking amazing!!! do you also teach vba? if yes am interested..

    Reply
  56. Trevor

    Hello,

    This is very useful, thank you very much.

    Just a few comments/questions:
    – In the version I downloaded, some cells do not have the same format as the others (I know this is not important, I just wanted to highlight it if not noticed yet)
    – Why did you not include an application.screenupdating = false/true (and application.calculation) in order to make the process faster?

    Best Regards,
    Trevor

    Reply
  57. Rahul

    Dear Vishwamitra,

    First of all thanks for sharing such a wonderful utility “File manager.”

    But the problem is it works only when option of list all files is selected for selective file extensions such as .pdf or .docx it won’t give any result.

    Can you pls sort out this problem.

    Thanks in advance 🙂

    Reply
    • Jorge Perú

      I have the same problem Rahui only works for .pdf

      Reply
  58. Jumana

    Hello Vishwamitra Mishra,

    I found this very interesting and useful; I am comparing documents in our companies shared drive as well as something called “sharepoint” a file sharing site. It has worked perfectly so far with the shared drive, but I was wondering if it will also take documents from sharepoint?

    Thank you soooo much for your help, you have been a life saver!!! 🙂

    Jumana

    Reply
  59. Mohit

    Thanks for the awesome work……u r great.

    Reply
  60. Hiren

    HI… .. Thank you soooo muchh. for your this post …I am very happy its very very usefull for me..thanks again….. I have one request please if you can help me.. I need one column list in that your Filemanager that contain video’s duration and the size in MB can you please help me?
    Thanks in advance .!!!

    Reply
  61. Dwi Budi

    great work..
    may i use some your code?
    i promise to keep your name and information on source code

    Reply
  62. Parth Shah

    Excellent!! Good Work.. Thanks..

    Reply
  63. SimpleSimon

    Fantastic, but can anyone assist in converting this for a MAC using a portable harddrive?

    Cheers

    Reply
  64. shetty

    hello Vishwamitra,

    I need a help. how can I copy files from folder and sub folder to another place which is older than 30 days.

    Reply
    • Mohamad

      The file stops working if the folder has big number of files
      lets say above 1000 files

      any way to solve this

      Reply
  65. Manish

    Awesome bro!!! very nice work….

    Reply
  66. Jason

    I do appreciate the lesson man.
    I’m aspiring to learn Macros to automate my office work and spend more time in the Site.

    Looking forward to learn and improve trough your guidance!

    More power and thank you very much.

    Reply
  67. JH Lu

    Hi Vishwa,

    The File Manager is a great tool, thank you! I noticed the latest version includes a file type selection. For some reason, the only file type that will pull correctly is the pdf. I have folders with Excel (xls, xlsx, xlsm) and Word documents, image files (jpg, gif, png, etc) but these aren’t fetched with the checkboxes checked. The “Fetch all types” does work.

    How do I get the checkboxes to work correctly?

    Thank you!!

    Jun-Hao Lu

    Reply
  68. Angelo

    Vishna fantastic work. Can’t say enough. If you ever tweak it could you please allow for showing just the folder rather then or including the path. On a network the path is far too long!! Only asking.
    Kind regards

    Reply
    • Chetan Khadke

      Hats off to you man !! This is amazing work you have done… saved a lot of my time… Thank you so much

      Reply
      • Vishwamitra Mishra

        You are welcome.. Chetan!!

        Reply
    • Vishwamitra Mishra

      Thanks Angelo for the feedback. I will consider this in the next version of the tool.

      Reply
    • Caspar

      Hi Angelo,

      find the line in the code where it says Cells(iRow,4).Formula, and replace it with the code below, that would do what you need.

      Cells(iRow, 4).Formula = Mid(FileItem.Path, Len(fPath) + 1, Len(FileItem.Path) – Len(fPath) – Len(FileItem.Name))

      Cheers!

      Reply
  69. Jue

    Thank you so much I have been giving myself a headache all day trying to get my VBA to work – then I found your file manager
    Absolutely superb! Thank you

    Reply
  70. Pete

    Hi Vishwamitra, I’ve been searching for a vba solution like this for ages and then you produce this fantastic piece of work, Thank you!

    I’m using Excel 2013 and I’m working on a very big project and this would be a great addition to it. Basically, in my vba project I want the end user to be able to select the folder/files in which they wish to import data and your File Manager would do the job. However; when I’ve run it, it’s not listing the .xlsx files within the selected folder. I know that the saved files are .xlsx as I’ve checked and checked and checked again but it just wont list them. Any ideas would be appreciated.

    Regards, Pete.

    Reply
  71. Satish Dubey

    Wow,
    What a fantastic piece of work.
    Congratulations brother.
    Long Live and create such wonderful things.

    God Bless

    Reply
  72. Owen Townes

    Spectacular! You made this week a whole lot easier on me. Thank you!

    Reply
  73. yehiasaid

    Peace,
    I would like to build a macro scene shifts to prepare weekly working arrangements for employees .
    Section should treat a certain output on a daily basis and contain several conditions inside ,
    For example an employee can work up to two evening shifts every week

    Reply
  74. Zaf

    hi

    Great work, I tried to run this macro for subfolders, but I am getting error message saying

    ListFilesInFolder not defined.

    Please help

    Reply
    • Popescu Adrian

      Hi,
      Just replace ListFilesInFolder with GetFilesInFolder

      Reply
  75. M ADil

    nice it working

    Reply
  76. Caspar

    Hi Vishwamitra,

    thanks for putting this together, very useful!
    However, the tool seems to only work for all files, not if you select only certain filetypes…

    any ideas?

    Reply
    • Iain

      There appears to be an error in the code for selecting file types.

      I got around this as follows

      Find the line below in ‘modFManager’
      arrList(j) = Left(Sheet1.ListBoxFileTypes.List(i), InStr(1, Sheet1.ListBoxFileTypes.List(i), “(“) – 1)

      Replace the last 1 with 2, so it reads as follows
      arrList(j) = Left(Sheet1.ListBoxFileTypes.List(i), InStr(1, Sheet1.ListBoxFileTypes.List(i), “(“) – 2)

      This should then work, or at least has for me.

      Reply
      • Lada

        Hello,
        thank you for application File Manager, but this fix doesn’t work.
        Only PDF documents can filters. Can you put in ListBox XLSM format?

        Reply
        • Vishwamitra Mishra

          Sure.. it will be available in the next version which I will be publishing it soon.

          Reply
  77. DB

    Hi Vishwamitra,

    thanks for putting this together, very useful!
    However, the tool seems to only work for all files, not if you select only certain filetypes…

    any ideas?

    Reply
  78. GavinRK

    Thank you. Simple to use and exactly what I was looking for. A work of art.
    Well done.

    Reply
  79. JJ

    Hi Vishwamitra,

    Thanks for your great tool. I have a question. I put a number at a specific cell in a specific sheet on every excel file. How to show it on the list?

    Reply
    • Vishwamitra Mishra

      What do you mean by “How to show it on the list?” which list are talking about? Can you please explain it by providing an example?

      Reply
  80. D. Smith

    Hello!

    This is great! Just curious, is there a way to list Folder names, in addition, to the File Names?

    Reply
  81. Tom

    Love this app right when I was trying to make something like this you arleady had it done even better. New to VB, I’ve found a way to have macro access secure IP address but I want to be able to pull files from a secure site where i have the access info like cloud or SVN respitory. Is that possible in macro?

    Reply
  82. Namal

    Thank you very mach Vishwa….. Highly appreciate

    Reply
  83. Saad

    is it okay if I use your VBA folder for work its a really good reference page and was wondering If it was okay If I used it

    Reply
  84. ralphy

    this is an amazing work. i appreciate very much you sharing it with the rest of the world. i used it to select all the excel files within a bunch of folders and subfolders and sub-sub-folders and added a little extra to resize the page layout for all of them. so thank you. you saved a lot of people from a time-consuming task.

    Reply
    • Vishwamitra Mishra

      Thank you so much for your lovely words. I am happy to help 🙂

      Reply
  85. Deb OReilly

    oh my, your program saved me hours of work. so quick, so easy. thank you so much for sharing!

    Reply
  86. Amit Kumar

    Wao OOO OOo………….. really works, thanks for saving my time

    Reply
  87. Martin

    Many thanks for the example spreadsheet, it saves me a lot of time.
    I have some feedback, when a file type is selected to fetch using the listbox, no results are returned in the table below. The fetch all types of files works as intended. Any ideas how I could fix this?
    Many thanks,
    Martin

    Reply
    • Vishwamitra Mishra

      Hi Martin,
      Glad it helped you saving your effort. Soon, I am releasing a new version where this bug will be addressed. Thanks for pointing out.

      Reply
  88. Abhishek Mishra

    Hello Vishwa,

    The File manager file is very useful to get the required file property. I am not sure how good you are with VBA FTP programming part.
    I just wanted to know if it is possible to check the same file present on local server and FTP server and based on which result can get generated.

    Can VBA be program to check if file present on FTP is same as local server by File attribute comparison and based on which result is generated such as “Old File on server”,”New file on server”,”File Size is not same”,”File not present on FTP” and so on.

    Your help on this will be fruitful
    Cheers !

    Reply
    • Vishwamitra Mishra

      Thanks Abhishek!! I am glad it helped you.

      I have never tried connecting to ftp via excel VBA. May be in future, I may have a look and share on this blog. But at this moment sorry, I can not help you.

      Suggestion:

      You may try these codes shared and let us know if it is working for you. Note: I have not tried this. Before running the code, please take a backup of your workbook. https://www.mrexcel.com/forum/excel-questions/261043-connecting-ftp-excel.html

      Reply
  89. Adam Walker

    Hi Vishwamitra

    I’m new to VBA (today actually). The tool is amazing, and I was wondering if you might be able to help with a couple of other things that I’d like to use it for re: photographs

    1) the dimensions of the photo
    2) Date taken
    3) Tags
    4) Author
    5) Title
    6) comments
    7) adding extra columns for the above and getting them to work (i can’t seem to get this working)
    8) new File formats for Office files and video file formats

    and if possible exporting a thumbnail of the image into a specific cell in excel corresponding to the details in earlier columns.

    Appreciate any help you can offer

    Reply
  90. M.Smith

    Hi Vishwamitra,

    I have just downloaded this, great tool. however as others have stated, it does not work when selecting specific file types.

    Have you a solution to this yet.

    Many thanks

    Mike

    Reply
  91. NS

    Superb !! Great tool to get file names from all Sub folders … I was searching this option since long & finally got this ….
    Thanks a lot for the wonderful tool..

    Reply
  92. Zsuiluj

    Hello Vishwamitra Mishra,
    Big help not only for me but for everyone.
    And everyone waiting for the updates to fix since the last time you update.
    Fetching all file types work fine but need to fix selecting some specific file types that doesn’t work.

    Reply
  93. Laxmikant

    Its really great and simple. Thanks a lot

    Reply
  94. Vinay

    HI Vishwamitra Mishra, I have created one excel data file for the calculation of client billing . On my excel formula using =count if funtion I get the result which is desired. (eg. if 100 clients data are available and 25 clients billing date is today, then using =countif formula I get the count as 25)

    My main motive is to also show the Client name of that 25 whose billing date is today.

    Please help me on this.

    Reply
  95. primo

    This is just Awesome! Exactly what I have been looking for. Thank you!

    Reply
  96. Darren

    Hi,
    Fantastic code. One thing though. How do you remove the file name from the file path?

    Reply
  97. Darren

    Fantastic code. Just one thing though. How do you remove the file name from the file path?

    Reply
  98. Larry

    Awesome but wondering how can we exclude the search in subfolders having a specific name. Like all subfolders called Old.

    Thxs

    Reply
  99. John

    I have been looking for something like this (Files from Folders and Sub-folders and list them. It fetches other details of the files as well like File Size, Last modified, path of the File, Type of the File and a hyperlink to open the file directly from the excel by clicking on that.) I clicked on the file (File_Manger) but when I click on “Fetch All File Details” button, nothing happens. Also the downloaded spreadsheet looks different that what is online. Pleas help. Thanks John.

    Reply
  100. Ije

    Thank you, this saved me alot of time.

    Reply
  101. Aribo

    hi ,
    When I try to export in excel I recieve an error “error occured while exporting. try again” and it keeps throwing that at me when trying again..
    What is going rong on mij computer or Excel/?

    Reply
  102. PAblo

    Hi,

    if you use it for listing folders and subfolders files it only lists the last subfolders files because the “r” variable’ value will be overwritten every time you call the function “GetFilesinFolder”

    Thank you

    Reply
  103. itr674

    Using Excel 2016.
    Getting several problems when trying to When trying to use “VBA code to List all files within a Folder and sub-folders as well”.
    1. when i hit run the macro listing window opens but Sub GetFilesInFolder is not listed in box?
    2. if I rename to Sub GetFilesInFolder () and comment out (SourceFolderName As String, Subfolders As Boolean) it will try to run, but get a Compile error at ListFilesInFolder?

    Reply
  104. Phillip Pfundt

    5/24/2019 Like the site– very user-friendly and a lot of stuff to see!

    Reply
  105. As

    Thanks Viswa,

    Very useful

    Aswani

    Reply
  106. Marcus

    File Manager in Excel has error in date (format).

    Hi Viswa. Interesting tool, however ..
    I was going to use this to detect duplicates in ANY folder (or location) on my work laptop as I’m not happy with the applications I found online and I’m not allowed to install them on my work laptop anyway..
    For accuracy I wanted to include, besides of the file name, the size and date. However some dates are not really dates.. just text. So they produce errors.

    It would be good to rectify this.. Also all dates in dd/mm/yyyy would be great!
    Cheers.

    Reply
  107. Jagdeep Khaira

    File Manager Utility is very good, thanks for posting and helping the community.
    Look forward for another similar macro for everyday help

    Reply
  108. Mahesh

    Excellent utility. Very helpful. Thanks!

    Reply
  109. Ken

    Hello Viswa,

    I see people are still commenting here so I’ll give it a shot. I’ve downloaded the tool and it works wonderfully but there is one piece missing. We need to get a list of all folders and files. Unfortunately, the tool does not list empty folders. We verified this today by adding a file to a folder that was empty and had not shown up. As soon as we added a file it showed up. What can we add to get empty folders to show up?

    Thank you!

    Reply
  110. Ken

    Vishwamitra…sorry.

    Reply
  111. Sachin Hardikar

    This is Excellent utility and it Very useful too, I need one modification if you can suggest. I also need to get blank or empty folder/directory list in folder path.

    Reply
  112. Niem

    Very smart

    Reply
  113. Andrew

    The file when I downloaded it fails to work, Excel tried to repair it but nothing worked. The page to download the macro book also failed to load and download.

    Reply
  114. David

    Thanks for your code. very usefull.
    I’ve made a few changes in order to work:
    In the second vba code, ListFilesInFolder should be GetFilesInFolder to make the recursive function work and the variable r should be defined as public outside the function, otherwise line are overwritten every loop.

    Reply
    • Nachelle

      Is there a way to execute the Fetch Files every 10 minutes or so?

      Reply
  115. Sanjaya Kularathne

    HI
    This is an amazing work. no words to appericate

    Reply
  116. Nachelle

    This is AWESOME!

    Thank you for all of your hard work!

    Is there anyway to automate this to fetch files every 10 minutes after pushing the fetch files button?

    Reply
  117. Marek

    Hello,
    Perfect tool when fetches on local drive in PC. But I have encounter a problem when path is set on server drive folder.
    It works but it is very slowly. For example the same folder structure on local drive was fetched let say immediately and for server path it took 14 minutes. Probably “something” on sever side is slowing down the process of getting FileScriptingObjects.
    I am not very sure if there is possibility in improving of it.. or maybe I am wrong.

    Reply
    • Marek

      Hello,
      I forgot to mention that to fetch folder/file structure from my company server drive was done via VPN and connection was about 6Mb/s.
      TI decided to go directly to the company were local drives are on 100Mb LAN. I tried it more times and it took about a few seconds. So it depends on network speed and latency. I have searched for some more info more explain the issue.

      See for this one please:
      https://stackoverflow.com/questions/18387447/vba-file-system-object-speed-advantages-disadvantages

      Maybe in case of network folders it could be solved by uising “Dir” function in looping instead of using File System Objects, e.g.:
      https://exceloffthegrid.com/vba-code-loop-files-folder-sub-folders/

      Reply
      • Marek

        Hello,
        Definitely using “Dir” function is solution for fetching folders and files!
        I have tried something with this one and it is in comparison to FSO very quickly!

        Reply
  118. Gábor

    Hello,
    First of all thank you for this fantastic work!
    Is there any way to add more than one searc folder?
    Thank you!

    Reply
  119. mritunjay

    hello viswa,

    i would like to ask you that is it possible to password protect this files from your sheet only with different passwords.?

    please reply….

    Reply
  120. Ajith

    This tool is really a good one,guess lot of effort been put on to built this…hats off…im trying to check just .txt files but it is not responding when i try to pull in file information from share drive.
    Though it works if ‘Fetch all types of File’ is checked.

    Reply
  121. Kim Cruz

    Thank you very much my friend! it helps me a lot.
    But actually i dont need the Files informations, i just need all the folders & sub-folders paths
    How do i do this?

    Reply
  122. Jefferson

    If some one needs expert view regarding running a blog after that i advise him/her to pay a visit this weblog, Keep up the
    good work.

    Reply
  123. Tejas Desai

    Great Work, I am so thankful for this work.

    Also, I was looking for an excel macro where If we have multiple images like 1000 images in a folder and if I want to search an image, then it will scan the folders and sub-folders and show the path of the relevant nearest match along with the photo.

    Is this possible??

    Reply
  124. Paul Someson

    When I open this program I get a “Method or data member not found”. in sub routine “Privite Sub Workbook_Open()” on the following line:

    Sheet1.ListBoxFileTypes.List = ArrFileType

    Thank You

    Reply
  125. ANAND

    Great.Very Very helpful.

    Reply
  126. Brian

    Awesome Tool! thank you for sharing!

    Reply
  127. Vishwamitra Mishra

    Thanks Anand!!

    Reply

Trackbacks/Pingbacks

  1. Learn Excel Macro Download Free File Manager in Excel Macro - [...] Hi Friends, I have created one file manager in Excel using excel macro. Basically it lists all the Files…
  2. MAcro to search multiple files in Folder and its subfolders and extracting their name and locatiey are on. - [...] in Folder and its subfolders and extracting their name and locatiey are on. you could try Learn Excel Macro…
  3. Need help adding author to indexing file - [...] Exit Sub err: MsgBox ("Error Occured while exporting. Try again") End Sub Here's the website: Learn Excel Macro How…
  4. VBA Save As Dialog - [...] || []).push({}); Hi, I wonder whether someone could help me please. From an article here: Welcome to LearnExcelMacro.com How…
  5. D-sub Out Of Range | Home - […] Welcome to LearnExcelMacro.com List All files from Folder … – i) User wants to get the list of All…
  6. Welcome to LearnExcelMacro.com How to create directory / folder using Excel VBA - […] Dear LEM Readers, Till now, I had published many articles on how to list files from a folder /…

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Join and get a FREE! e-Book

Don't miss any articles, tools, tips and tricks, I publish here

You have Successfully Subscribed!

Pin It on Pinterest