-1

I have a folder which contains four further folders.

  • 20180304
  • 20180412
  • 20180622
  • 20170702

I want to see when get the searched file leatest, so I need to find the file in these folders and the connected folder names dinamically. How can I do it? Thanks in advance.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
blackcornail
  • 155
  • 1
  • 2
  • 10
  • 2
    Possible duplicate of [Loop through files in a folder using VBA?](https://stackoverflow.com/questions/10380312/loop-through-files-in-a-folder-using-vba) – Pᴇʜ Jul 13 '18 at 10:02
  • This question has been answered more than 10 times I think. Do some research before you ask ([ask]). And if you still have a question, show what you researched so far and what you have tried by showing your code in the question. – Pᴇʜ Jul 13 '18 at 10:04

1 Answers1

1

You can use a For Each loop once you provide the root folder.

Example:

Create an instance of the FileSystemObject

Set objFSO = CreateObject("Scripting.FileSystemObject")

Get the folder object

Set objFolder = objFSO.GetFolder("C:\Temp")

loops through each folder in the directory

For Each objSubFolder In objFolder.subfolders
    **Handle Code Goes Here**
Next objSubFolder

So now you have each subfolder of the root folder you provided (C:\Temp) in this case, you can do something like this to get information:

String1 = objSubFolder.Path 
String 2 = objSubFolder.Name
Petay87
  • 1,700
  • 5
  • 24
  • 39