logo elektroda
logo elektroda
X
logo elektroda

Creating Excel List of Files, Subfolders, and File Sizes Using VBA Macro

slawek1100 13947 8
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 16523012
    slawek1100
    Level 10  
    Hello,

    I am facing the problem of preparing an excel list of files in folders and subfolders. The problem is that in a specific location (e.g. C: \ Files) I put a certain set of folders, usually 5 polders, then I need to download data from excel files located in these folders and subfolders. I have a macro that retrieves data from folios, but it requires that the macram file be in the last subfolder with excel files, and that the macro would download the list of subfolders from the C: \ Files location. I would like to mention that the depression looks like this: C: \ Files \ Subfolder (usually 5) \ Subfolders (usually 6) \ excel (xlsx) files. A file size would also be useful. Ultimately, I would like the list in excel to be created:

    Location Files File size
    C: \ Files \ Subfolder 1 \ Subfolder1 | file1.xlsx | 540
    C: \ Files \ Subfolder 1 \ Subfolder1 | file2.xlsx | 540
    C: \ Files \ Subfolder 1 \ Podfolder2 | file1.xlsx | 540
    C: \ Files \ Subfolder 1 \ Subfolder ... | file1.xlsx | 540
    C: \ Files \ Subfolder 2 \ Podfolder1 | file1.xlsx | 540
    C: \ Files \ Subfolder 2 \ Podfolder2 | file1.xlsx | 540
    C: \ Files \ Subfolder 2 \ Subfolder ... | file1.xlsx | 540
    C: \ Files \ Subfolder 3 \ Podfolder1 | file1.xlsx | 540
    C: \ Files \ Subfolder 3 \ Subfolder ... | file1.xlsx | 540
  • ADVERTISEMENT
  • ADVERTISEMENT
  • ADVERTISEMENT
  • #4 16523145
    JRV
    VBA, Excel specialist
    Opss .. for me max XL2007
  • #5 16523170
    slawek1100
    Level 10  
    It's a pity I'll keep looking. Thanks for the help

    Added after 27 [minutes]:

    I was able to determine that Application.Filesearch has been down since excel 2010, but I don't know what to replace
  • Helpful post
    #6 16523215
    adamas_nt
    Moderator of Programming
    And what if "ordinary" Dir?
    Code: VBScript
    Log in, to see the code
  • ADVERTISEMENT
  • #7 16523251
    slawek1100
    Level 10  
    That would be it, but it is already too late, or I do not have the knowledge to correct this code to the system I need, i.e. where to insert a loop that will create a path in wheel A, in file B the name of the file and in file C its size :(
  • Helpful post
    #8 16523315
    lanzul
    Level 30  
    slawek1100 wrote:
    That would be it but it is too late ... :(

    THIS IS IT ... :D ... and I don't think it's too late for anything ... :D ... e.g. for a brewery ... :D ... well, unless it's about quotes from Stachura ... :) ... and certainly not too late to thank a colleague adamasowi_nt ...

    slawek1100 wrote:
    where to insert the loop that will create

    No need ... loops are already ... one additional variable per row counter and game cabinet ...

    adamas_nt wrote:
    And if so "ordinary" Dir'em ...

    With the permission of a friend ... :) ...:
    Code: text
    Log in, to see the code
  • #9 16524856
    slawek1100
    Level 10  
    GOD, IT IS IT !!!! :lol: it will save me a lot of time. :ok: BEER for you. Thank you very much!!! :please:

Topic summary

The discussion revolves around creating an Excel list of files, subfolders, and their sizes using a VBA macro. The user seeks a solution to compile data from a specific directory structure (C:Files) containing multiple subfolders and Excel files. Initial attempts to use commands like "colFilesFullNames" and "With Application.FileSearch" were unsuccessful due to compatibility issues with Excel 2016. A suggested solution involves using the "Dir" function along with the FileSystemObject to iterate through subfolders and files, capturing their paths and sizes. The final VBA code provided includes a loop to populate an Excel sheet with the desired information, which the user found highly beneficial.
Summary generated by the language model.
ADVERTISEMENT