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

Delete Message with VBA



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old June 20th 08, 06:11 PM posted to microsoft.public.outlook.program_vba
Luis
external usenet poster
 
Posts: 13
Default Delete Message with VBA

Can someone let me know how to delete four messages in a Folder? I have tried
to find information on it but there is not VBA code samples. Use the code
below but it does not delete all the messages.

For Each MailItem In MyFolder.Items
Debug.Print MailItem.Delete
Next MailItem

Any suggestions and/or guidance will be helpfull.

Luis
Ads
  #2  
Old June 20th 08, 08:00 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Delete Message with VBA

Do not use for each or a loop from 1 to Items.Count since deleting will
change the count.
Use "for i=Items.Count to 1 step -1" instead

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Luis" wrote in message
...
Can someone let me know how to delete four messages in a Folder? I have
tried
to find information on it but there is not VBA code samples. Use the code
below but it does not delete all the messages.

For Each MailItem In MyFolder.Items
Debug.Print MailItem.Delete
Next MailItem

Any suggestions and/or guidance will be helpfull.

Luis



  #3  
Old June 20th 08, 08:02 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Delete Message with VBA

You need to use a countdown loop instead:

c = MyFolder.Items.Count
For i = c to 1 Step -1
Set MailItem = MyFolder.Items(i)
MailItem.Delete
Next
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Luis" wrote in message ...
Can someone let me know how to delete four messages in a Folder? I have tried
to find information on it but there is not VBA code samples. Use the code
below but it does not delete all the messages.

For Each MailItem In MyFolder.Items
Debug.Print MailItem.Delete
Next MailItem

Any suggestions and/or guidance will be helpfull.

Luis

 




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
Can't Delete Message longmere Outlook Express 5 June 29th 08 05:05 PM
Can't delete a 19 meg. message TC Outlook Express 1 January 27th 08 11:02 PM
Outlook does not want to delete message Deon Outlook - General Queries 4 February 23rd 07 08:19 PM
How do you delete a message from a Newsgroup? SHERRY MANZANO Outlook Express 7 May 27th 06 09:59 PM
Message Delete Won't Work Alex W. Outlook Express 4 May 23rd 06 08:11 PM


All times are GMT +1. The time now is 08:05 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.