For Each Question

  • Thread starter Thread starter Steve Roberts
  • Start date Start date
S

Steve Roberts

In the code below I would like to move to the next folder in the collection
if any of the IF...THEN items are true. I keep seeing ways to exit the loop
but not to increment and skip part of the loop.

Any suggestions would be appreciated
Steve

For Each olNewFolder In CurrentFolder.Folders

Debug.Print olNewFolder.Items.Count

If olNewFolder.Name = "Deleted Items" Then ' go to the
Next folder
If olNewFolder.Items.Count <= 1 Then ' go to the Next
folder
If olNewFolder.DefaultItemType = olContactItem Then ' go to
the Next folder
If olNewFolder.DefaultItemType = olAppointmentItem Then ' go
to the Next folder

MyNameSpace.AddStore "c:\" & olNewFolder.Name & ".pst"
Set objFolder = MyNameSpace.Folders.GetLast '.GetLast Set
objFolder to last folder
objFolder.Name = olNewFolder.Name ' change the name that the user
sees in outlook

ProcessFolder olNewFolder 'Call Process Folder to actually perform the
move

End If

Next
 
You never ever should try to manipulate a For loop counter from within
the loop. Just use your If tests, nested if necessary, and only
execute the loop body if all the If tests are true. An alternative
would be to code the tests as part of a Select Case construct.
 
Back
Top