iknowu99
Well-known Member
- Joined
- Dec 26, 2004
- Messages
- 1,158
Application.FileSearch is nested >> do they interfere? specifically the with statements
Code:
Sub withINSIDEwith()
'mock example
With Application.FileSearch
.LookIn = "C:\abc\"
.Filename = "*.xls"
.FileType = msoFileTypeExcelWorkbooks
.SearchSubFolders = True
.Execute
If .Execute > 0 Then
'loop through all found files
For IFoundFiles = 1 To .FoundFiles.Count
'set incidental variables
Pos = InStrRev(.FoundFiles(IFoundFiles), "\")
file = Right(.FoundFiles(IFoundFiles), Len(.FoundFiles(IFoundFiles)) - Pos)
path = Left(.FoundFiles(IFoundFiles), Pos)
Set wb = Workbooks.Open(path & file)
'do some stuff here
'********
'do some stuff here
With Application.FileSearch
.LookIn = "C:\jk\"
.Filename = "Foo*.xls" 'a different file is found here
.FileType = msoFileTypeExcelWorkbooks
.SearchSubFolders = True
.Execute
If .Execute > 0 Then
'loop through all found files
For KfoundFiles = 1 To .FoundFiles.Count
'set incidental variables
pos2 = InStrRev(.FoundFiles(KfoundFiles), "\")
file2 = Right(.FoundFiles(KfoundFiles), Len(.FoundFiles(KfoundFiles)) - pos2)
path2 = Left(.FoundFiles(KfoundFiles), pos2)
Set wb2 = Workbooks.Open(path2 & file2)
'do more stuff here
'********
'do more stuff here
Next KfoundFiles
End If 'If .Execute > 0 Then
End With
Next IFoundFiles
End If 'If .Execute > 0 Then
End With
End Sub