IT_Crowd
asked on
Word VBA Code to Traverse Files in a Folder Alphabetically
I have a macro that traverses two folder structures, checks for Word documents within those folder structures and outputs the results to a text file. These output files are then referenced in customized tabs within Word.
Unfortunately, these folders are not showing up within Word as "sorted alphabetically". I've verified that Windows explorer is seeing these folders and files sorted alphabetically, but is there a way to force the VBA code to see or sort the folders in alpha order?
I have attached some segments of code along with an example of the output and end result. Thanks for the help!!
CreateTemplates-Macro.txt
ExampleOutput.txt
Tab-Drop-Down.png
Unfortunately, these folders are not showing up within Word as "sorted alphabetically". I've verified that Windows explorer is seeing these folders and files sorted alphabetically, but is there a way to force the VBA code to see or sort the folders in alpha order?
I have attached some segments of code along with an example of the output and end result. Thanks for the help!!
CreateTemplates-Macro.txt
ExampleOutput.txt
Tab-Drop-Down.png
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the ideas. I'm really like the dir command idea right now, I think it will be pretty easy to work with, and I think my code could use a rework anyways.
ASKER
I'll use the DIR command in VBA to get the results I want. Thanks!
If you omit the /b flag from the DIR command, you can use the following regexp patterns to parse the results. The first one gives you directory matches and the second one parses the docx/docm file names within each match.
Directory of ([^\r]*)\s+((?:.|\n)*?)\d bytes
\d.{36}\d (.*?\.doc[xm])
you could use a collection to sort it
Open in new window
Regards