I am trying to loop through all the folders within a sub-folder in Outlook to see if the string is inside an Excel sheet.
The loop is skipping some folders and so I have to rerun the macro. While debugging The loop skips three items in a test case.
Dim outlookFolder As Variant
Dim numOutlookFolders As Integer: numOutlookFolders = 0
Debug.Print POFolder.Folders.Count
For Each outlookFolder In POFolder.Folders
Found = False
For Each PO In tbl.ListColumns(1).DataBodyRange.SpecialCells(xlCellTypeVisible)
If InStr(outlookFolder.Name, PO) Then
Found = True
'Exit For
End If
Next PO
If Found = False Then
If InStr(outlookFolder.Name, "PO") Then
outlookFolder.MoveTo CompletedFolder
Dim folderName As String: folderName = outlookFolder.Name
fileStream.WriteLine folderName
Count = Count + 1
End If
End If
numOutlookFolders = numOutlookFolders + 1
Next outlookFolder
Debug.Print numOutlookFolders
Debug Window Output:
49
46