Forum

VBA find file with ...
 
Notifications
Clear all

VBA find file with criteria

6 Posts
3 Users
0 Reactions
93 Views
(@learning2)
Posts: 5
Active Member
Topic starter
 

Hello

I have found code to list and hyperlink all files within a directory but is there a way with VBA to search for files from a directory with 3 sub folders using an inputted cell value with a wildcard, then list the subfolder name as a hyperlink and with the files found?

For example the cell A1 could be inputted with 1234*, B2 would contain the directory path.

The found file names would then appear in column C and the containing folder name appear in column B as a hyperlink.

 
Posted : 28/03/2017 7:54 am
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Learning2

See if this is what you wanted.

Please do not key an asterisk (*) in cell A1. Just enter 1234 and it will search for all file names containing 1234.

Normally the file name is hyperlinked, not the folder's name. Anyway I hyperlinked both.

Cheers

Sunny

 
Posted : 28/03/2017 10:49 pm
(@learning2)
Posts: 5
Active Member
Topic starter
 

Hi Sunny

That is exactly what I was looking for 🙂

I have around 8000 files in one folder so it takes a while to process but does the job perfectly!

 

Thank you

 
Posted : 29/03/2017 6:58 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi,

Not sure what your own code does but these may add something

https://www.myonlinetraininghub.com/create-hyperlinked-list-of-files-in-subfolders

https://www.myonlinetraininghub.com/create-hyperlinked-list-of-files-in-a-folder-using-vba

Regards

Phil

 
Posted : 30/03/2017 12:18 am
(@learning2)
Posts: 5
Active Member
Topic starter
 

Hi Phil and thanks for responding,

I basically have a multitude of subfolders in a main folder and wished to find files in the subfolders that start *nnnn-nn* (n being a number) and what subfolder it is in with both the file and sub folder reported as hyperlinks.

Sunny' code uses the value from cell A1 instead of an input box and not too dissimilar in principle

 Hyperlinked File List in Single Column works faster in comparison with Sunny' code but are similar in size in terms of coding?

Could you help me understand the difference to the hyperlinking and Sunny's coding - Hyperlinks.Add_Anchor:=ActiveSheet.Range("C" & xNextRow), _   Address:=xFile.Path, TextToDisplay:=xFile.Name so I can make the holding folder a hyperlink also.

Would be good if the subfolders (paths) that does not contain any *nnn-nn* files could be omitted in the result

 
Posted : 30/03/2017 7:36 am
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Learning2

You did ask that the macro to look into cell A1 so that's what I did. Smile

For example the cell A1 could be inputted with 1234*, B2 would contain the directory path.

The found file names would then appear in column C and the containing folder name appear in column B as a hyperlink.

If speed is a concern, then Philips code will do, although I would prefer my file names to be in a single column so that I can sort them. Also DIR() cannot display Chinese characters while FSO can do that (and I need that).

Choose whichever that suit you.

Cheers

Sunny

 
Posted : 30/03/2017 11:57 pm
Share: