Review of code to send all draft messages ...

  • Thread starter Thread starter M100C
  • Start date Start date
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
 
That approach is fine. An alternative would be a countdown For ... Next loop.
 
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.
 
Back
Top