PDA

View Full Version : Retrieving all files in folder or subfolder containing specific text



Meido
08-07-2019, 07:42 AM
Hi everyone, this is my first post here so please be patient with me.

I am looking to create a macro that looks through all files in a folder and its subfolders (and potentially expand it later to look through the whole drive) that contain a specific ID (alpha-numeric with symbols, not sure if that makes a big difference). Ideally I would like to retrieve the files, but a list of the files that contain that text would be good too.

I am not asking for the code to do it, I am learning how to use VBA and would like to do it myself to improve my learning process. I would really appreciate some guidance towards where to start and what resources that some of you know about (preferably free) that I can use to learn the tools and coding skills I can use to develop this and further my understanding of the process of creating complex macros.

Any help or direction is very much appreciated!

Thank you!

Jan Karel Pieterse
08-07-2019, 07:53 AM
Is this ID in the name of the file or in the content of the file?

Meido
08-07-2019, 08:09 AM
Thanks for the quick reply!

In some it would be in both, but I would want to retrieve any file that contains that ID.

Jan Karel Pieterse
08-07-2019, 08:24 AM
If it's just in the name you can use Data, Get Data, From FIle, From Folder.

Meido
08-07-2019, 01:16 PM
Sorry for the late reply!

Well the idea is that I'd like it to open the files that contain that ID or provide me with a list whenever I enter in a different ID if that makes sense. I'd want to search for an ID and open or provide a list of all the files that contain that ID.

For example: I'd type in 1A-2B-C3 and have it retrieve all files that contain that ID, then do the same for another ID like 2A-1B-C3 and so on.

Jan Karel Pieterse
08-08-2019, 12:37 AM
That would be a very slow process as each file would have to be opened. One way to do this is by using file indexing and searching software. LIke the ones discussed here: https://www.lifewire.com/11-free-file-search-tools-1356644

KimP
08-08-2019, 01:22 AM
I know this is potentially not what you're looking for, but if I'm understanding correctly, you could use Power Query to achieve this.
This would work well assuming the files are in the same/similar format. It largely depends on what you're end goal is.

I won't go into anymore detail yet because it is probably not what you're looking for but let me know if you want to explore this further.

snb
08-08-2019, 05:24 AM
Windows has that searching option built-in.
VBA can't add anything to that option.

To learn VBA you should start simply, using the library of a specific Office Program: Excel, Word, Powerpoint, Access, Outlook