
Originally Posted by
mudraker
Here is some examples to get the file name to be opened & file named for file to be saved as.
The 1st example will show all files in a folder
There are other ways of acheiving what you require - I find using one of these methods the easiest to code & work with
Thanks for your advice Mudraker, but I'm afraid that's not what I'm looking for. I'd like the code to accept as input a starting directory, preferably selected through the File->Open dialog box. Once the directory is selected, the code should pull all the folders, files, subfolders and subfiles in as text, and put them into the spreadsheet, one on each line, with their full path, filename, and extension.
I _can_ get this data by doing the following command in DOS:
And I _can_ run that command through a .bat file, which captures every file down to the last subfolder. So, at the very least, I'd like to make Excel do the following:
1) Let the user browse to a directory to be cataloged.
2) Take the path of the selected directory and use it to make a customized .bat file (replacing "C:\DESIGN_DATA" in the above example w/ whatever the user's selected).
3) Executing that .bat file to build the .txt file containing the full file listing.
4) Import that .txt file into Excel such that each line in the .txt file is one cell in Excel.
I've gleaned some pieces of this functionality from other people's posts here and have the following:
To browse to a file:
To make a .bat file:
To run a .bat file:
However, I've also seen some examples around here of using VB straight in Excel to replicate the DIR type behavior, without needing to resort to a .bat file running DOS commands. My instincts tell me that I'm making this overly complicated by trying to use .bat files, but I don't have th VB experience to get the directory listing, and especially not in a single, one-line command.
Bookmarks