For Each Question

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
 
K

Ken Slovak - [MVP - Outlook]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top