0

I am using this script to find a sub-folder with a specific string (in this case 300) in the main directorys main path.

Sub Find_SubFolder()
Dim sFile As String, sPathSeek As String, sPathMatch As String

Const sMainPath As String = "C:\Users\502158766\Desktop\testje\"

On Error Resume Next
sPathSeek = sMainPath & 300 & " " & "*"
sFile = Dir(sPathSeek, vbDirectory)

Do While Len(sFile) > 0
    If Left(sFile, 1) <> "." Then
        If (GetAttr(sFile) And vbDirectory) = vbDirectory Then
            sPathMatch = sFile
            Exit Do
        End If
    End If
    sFile = Dir
Loop

MsgBox IIf(sPathMatch = "", "Match not found", "Found in: " & sMainPath & sPathMatch)
Call Shell("explorer.exe " & sMainPath & sPathMatch, vbNormalFocus)
End Sub

I am looking for an upgrade of this script allowing to check every sub-folder starting from the main directory to do the same (search and open folder which contains 300) Furthermore the script should open the highest sub-folder in line.

For example : My main directory holds the following maps :

C:\Users\502158766\Desktop\testje\fruit\apples\30 greens\30 fromENG

C:\Users\502158766\Desktop\testje\fruit\apples\30 greens\30 fromUSA

C:\Users\502158766\Desktop\testje\fruit\apples\30 greens\30 fromBELG

C:\Users\502158766\Desktop\testje\fruit\apples\30 greens\30 fromNL

C:\Users\502158766\Desktop\testje\fruit\apples\30 greens\30 fromCYP

C:\Users\502158766\Desktop\testje\fruit\banana\15 greens\15 fromENG

C:\Users\502158766\Desktop\testje\fruit\banana\15 greens\15 fromUSA

C:\Users\502158766\Desktop\testje\fruit\banana\10 greens\15 fromBELG

C:\Users\502158766\Desktop\testje\fruit\banana\20 greens\15 fromNL

C:\Users\502158766\Desktop\testje\fruit\banana\50 greens\15 fromCYP

The script should now open the 30 greens map in case 30 is in path-seek. And in case 15 is in path-seek, it should open the 15 greens map and not the others.

I've been trying yesterday and I found a way to open all folders in the main directory and use a combination of text to column follow the hyper-link to the highest sub-folder. However it's been a real hassle with the script crashing due to many files.

Hope my question is clear, Thanks a lot guys!

Ruddy
  • 9,795
  • 5
  • 45
  • 66
JelleL
  • 1
  • have a look in [**here**](http://stackoverflow.com/questions/17461935/vba-macro-to-mass-update-multiple-files-in-same-location/17470628#17470628) –  Oct 31 '13 at 08:49
  • I can understand you are using this option in a part of your script (which is very nice btw). However, I am afraid I don't have the knowledge to adjust it to my needs. – JelleL Oct 31 '13 at 09:12

1 Answers1

0

Have a look here . It almost works. I think you'll need to add the apth to SFile when calling "GetAttr(sFile)"

user3579314
  • 69
  • 1
  • 3