Review of code to send all draft messages ...

M

M100C

All,
I have written some VBA to loop through the items in my Drafts folder
and send each one.

I am not very familiar with the Outlook object model, or their
properties and methods. My first inclination was to "do something"
with each item in the folder, but the Send method effectively removes
the item from the folder.

The code below seems to work well. If I have the correct
understanding, items are indexed beginning at 1, so if my Drafts
folder contained 30 items, the code will execute inside the loop until
all messages are sent (.Count = 0), while assuring that an item is
always in scope.

Do Until myDrafts.Items.Count = 0

myDrafts.Items(1).Send

Loop

This group has a lot more experience than I have with Outlook VBA; is
this the best way to do this ... to me, it just seems there may be a
better option.

Take care,
Chris
 
S

Sue Mosher [MVP-Outlook]

That approach is fine. An alternative would be a countdown For ... Next loop.
 
E

Eric Legault [MVP - Outlook]

If you are working with a collection where the number of items change as you
work with them, then you need to do a special loop:

For intX = Items.Count To 1 Step -1
'Do something
Next

This way it always works with the last item - until there are no more items.
 

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