Super Suarez
Registered User.
- Local time
- Today, 02:34
- Joined
- Jul 10, 2013
- Messages
- 36
Hi,
This code below works, but alot of what it does is unnecessary. I have a directory structure named 1000-2000, 2001-3000, 3001 - 4000 etc and within that is the individual folders 1000, 1001, 1002 etc
How do I test to search top level folder thats no larger than correctNum to then test the subfolder for correctNum? I've looked at instr and a few other funtions, but can't find a solution. Below is what I have now, it works but I know it searches everything and that's not correct
Dim filesys
Dim Subdir
Dim folder
Set filesys = CreateObject("Scripting.FileSystemObject")
Dim oDir
Dim bDir
CorrectNum = Serial.Value
If IsNull(PumpNum) Then GoTo function_finish:
searchfolder = "C:\archive temp"
pfile = False
Set oDir = filesys.GetFolder(searchfolder)
For Each Subdir In oDir.SubFolders
Set bDir = filesys.GetFolder(Subdir)
For Each folder In bDir.SubFolders
If InStr(1, folder, CorrectNum) > 0 Then pfile = True
If InStr(1, folder, CorrectNum) > 0 Then GoTo function_end:
Next folder
Next Subdir
function_end:
If pfile = True Then MsgBox ("good")
If pfile = True Then Shell "Explorer.exe /n,/e," & folder, vbNormalFocus
function_finish:
If IsNull(PNum) Then MsgBox ("no serial num!")
Appreciate your time
This code below works, but alot of what it does is unnecessary. I have a directory structure named 1000-2000, 2001-3000, 3001 - 4000 etc and within that is the individual folders 1000, 1001, 1002 etc
How do I test to search top level folder thats no larger than correctNum to then test the subfolder for correctNum? I've looked at instr and a few other funtions, but can't find a solution. Below is what I have now, it works but I know it searches everything and that's not correct
Dim filesys
Dim Subdir
Dim folder
Set filesys = CreateObject("Scripting.FileSystemObject")
Dim oDir
Dim bDir
CorrectNum = Serial.Value
If IsNull(PumpNum) Then GoTo function_finish:
searchfolder = "C:\archive temp"
pfile = False
Set oDir = filesys.GetFolder(searchfolder)
For Each Subdir In oDir.SubFolders
Set bDir = filesys.GetFolder(Subdir)
For Each folder In bDir.SubFolders
If InStr(1, folder, CorrectNum) > 0 Then pfile = True
If InStr(1, folder, CorrectNum) > 0 Then GoTo function_end:
Next folder
Next Subdir
function_end:
If pfile = True Then MsgBox ("good")
If pfile = True Then Shell "Explorer.exe /n,/e," & folder, vbNormalFocus
function_finish:
If IsNull(PNum) Then MsgBox ("no serial num!")
Appreciate your time