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

sample code to delete items in folder 24 hours old



 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old September 3rd 08, 04:55 PM posted to microsoft.public.outlook.program_vba
Tom[_7_]
external usenet poster
 
Posts: 7
Default sample code to delete items in folder 24 hours old

I have the following code sample in ThisOutLookSession and when I set a
breakpoint and step through the code, it does show the correct number of
items in Deleted Items folder - but does not delete them, no errors either

Sub CustomMailMessageRule (Item as Mailitem)

' at the very end of it, this is called
Call DeleteAllMailNotReceivedToday

End Sub

Sub DeleteAllMailNotReceivedToday()

Dim DL as outlook.items
Dim Om as Mailitem
Dim i as integer

set DL =
application.getnamespace("MAPI").getdefaultfolder( olfolderdeleteditems).items
for i = DL.Count to 1 step -1
set Om = DL.Item(i)
if datediff("h",Om.receivedtime, now()) 24 then Om.Delete
next
set DL = nothing
set Om = nothing

End Sub



 




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
sample code for empty deleted items folder Tom[_7_] Outlook and VBA 3 September 4th 08 04:00 PM
Trying to find sample code for import from Excel Dale Bennett Outlook - Using Forms 0 October 11th 07 07:17 PM
What are the correct Dim statements to go with this Microsoft Sample Code? Bill Outlook and VBA 4 April 27th 07 08:08 PM
Sample Code for Merge With Attachments? LongWayFromHome Outlook and VBA 13 August 18th 06 05:04 PM
Junk E-mail folder - is there a way to create a rule to delete items in this folder older than X days? Jaycee Outlook - General Queries 1 February 22nd 06 04:54 PM


All times are GMT +1. The time now is 06:12 AM.


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.