A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Review of code to send all draft messages ...



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old September 13th 07, 05:28 PM posted to microsoft.public.outlook.program_vba
M100C
external usenet poster
 
Posts: 1
Default Review of code to send all draft messages ...

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

Ads
  #2  
Old September 13th 07, 05:36 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Review of code to send all draft messages ...

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

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"M100C" wrote in message ups.com...
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

  #3  
Old September 13th 07, 06:32 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default Review of code to send all draft messages ...

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.

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"M100C" wrote:

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


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Send Email from Draft Folder DennyP Outlook - General Queries 11 January 29th 10 02:18 PM
Outlook Express 6 - Draft Email Icons on Desktop - Unable to use in draft form [email protected] Outlook Express 1 October 13th 06 11:58 AM
Why do I have to hit send/receive to review new messages? No3Sista Outlook - Calandaring 1 October 12th 06 05:06 AM
draft messages don't close when outlook closes [email protected] Outlook - General Queries 1 July 13th 06 04:57 AM
Macro to Move Mail Messages from Draft folder to other folders VBnovice Outlook and VBA 4 June 14th 06 07:10 PM


All times are GMT +1. The time now is 06:11 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.