vba file handling

  • Hello,

    I have come to a point in a VBA program where I could do with improving the code by including some basic file handling. What I basically want is for Excel to count the number of files in a specified directory and then loop that amount of times until all the fully qualified paths are stored in a variable array so the user can access them later in the program.

    Any advice is much appreciated

    Many thanks

  • Re: vba file handling


    Attached is a code which does that...not mine found on this forum a while ago
    The code allows the user to select a folder and all the files of designated filter are extracted to an array

    Filenameslist is the array
    You can replace the *.txt, with any file filter
    The false or true is for searching subfolders

    FileNamesList = CreateFileList("*.txt", False)

    This is the code you have to add to a module


  • Re: vba file handling

    Hi Mark

    The code below should help. It is set to open all xls files in a specified folder. You can however modify it so all Workbook names are passed to a String Array

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!