Delete emails from Inbox

Hello guys !!  I need to delete or move from my inbox to the trash bin or just out of outlook all my emails except those with today's date.
How can I do this?
Thanks
Mighty_EdAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

war1Commented:
Greetings, Mighty_Ed !

Click on the Inbox; then put cursor in email list. Hit CTRL + a  which will highlight all the emails in the Inbox. Holding the CTRL key, click on each email from today, which will un-highlight the email.  Then hit Delete key to delete all the highlighted emails or right click on a hightlighted area and select Delete.

Best wishes!
0
Craig321Commented:
Hello,

Another way to do this would be to click the newest on top column title, this will put your newest emails at the top of the view page. Then click the first email you want deleted, scroll to the bottom email you want deleted, hold shift and click it, this will highlight both the first and second emails and also all the ones in between. Then hit enter to delete them :)

Craig.
0
Mighty_EdAuthor Commented:
ok, maybe i forgot to mention, I want to do this automatically like a rule or a script so I don't have to do this every 3 days at my boss' house.
Because it's a replica of the emails at the office he only wants to see the current day in case he missed one or two emails
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

David LeeCommented:
Greetings, Mighty_Ed.

Here's a script that deletes everything in the Inbox that's more than 24 hours old.  We can run this manually, by tthe click of a button, or automatically (e.g. every time Outlook starts or is shutdown).  Let me know what you're preference is and we'll take it from there.

Sub DeleteAllMailNotReceivedToday()
    Dim olkInbox As Outlook.Items, _
        olkItem As MailItem, _
        intIndex As Integer
    Set olkInbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
    For intIndex = olkInbox.Count To 1 Step -1
        Set olkItem = olkInbox.Item(intIndex)
        If DateDiff("h", olkItem.ReceivedTime, Now()) > 24 Then
            olkItem.Delete
        End If
    Next
    Set olkInbox = Nothing
    Set olkItem = Nothing
End Sub

Cheers!
0
Mighty_EdAuthor Commented:
well, it can be at startup.
Hope you can tell me exactly how to make this script work.  If you tell me with details I'll give 500 points
Thanks
0
David LeeCommented:
Ok, here's the code revised to run each time Outlook starts.  Follow these instructions to use it.

1.  Start Outlook
2.  Click Tools->Macro->Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
4.  Copy the code below and paste it into the right-hand pane of the VB Editor window
5.  Click the diskette icon on the toolbar to save the changes
6.  Close the VB Editor
7.  Click Tools->Macro->Security
8.  Set the Security Level to Medium.  
9.  Close Outlook
10.  Start Outlook
11.  Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run.  Say yes.

That's it.  Each time Outlook is started this code will run and delete everything in the Inbox that's over 24 hours old.

Private Sub Application_Startup()
    Dim olkInbox As Outlook.Items, _
        olkItem As Object, _
        intIndex As Integer
    Set olkInbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
    For intIndex = olkInbox.Count To 1 Step -1
        Set olkItem = olkInbox.Item(intIndex)
        If DateDiff("h", olkItem.ReceivedTime, Now()) > 24 Then
            olkItem.Delete
        End If
    Next
    Set olkInbox = Nothing
    Set olkItem = Nothing
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mighty_EdAuthor Commented:
any way in which I can avoid the message to choose to run or not the macros?
0
David LeeCommented:
You can lower the macro security level to Low, not recommended, or you can sign the code with a certificate.  Here's a link to instructions for doing that:   http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnoxpta/html/odc_dsvba.asp

Don't be put off by the fact that the instructions are for XP.  They work for 2003 too.
0
Mighty_EdAuthor Commented:
Thanks everything worked perfectly and trasnparent for the user.
You rock. Please let me know if you received the 600 points
0
David LeeCommented:
Thanks!  You're welcome.  I don't know about 600 points.  I received 1000 points (250 * 4 for the A).
0
Mighty_EdAuthor Commented:
cool
so we are done !!!
thanks again
0
ibcjapanCommented:
I tried the script and got the error msg that says: 'Run Time error '438':    'Object doesn't support this property or method'. I'm tried using MS Outlook 2000 and 2003 version. Any advice on this error?
0
David LeeCommented:
Hi, ibcjapan.

What line are you getting the error on?  Did you follow the directions exactly?
0
fredfromnowonCommented:
Hi - VERY new here. Actually this is my first post so please be understanding with that.

I have an EU who wants to have their email in the Inbox deleted after 120 days. I modified this script above to the time of 2880 instead of 24. However when I run this script on his system (Win XP and Outlook 2003) I get the Run Time Error 438  - when I choose debug it shows there to be a problem with this line
If DateDiff("h", olkItem.ReceivedTime, Now()) > 2880 Then

Can you help me out with this, please?
Thanks - Erik
0
David LeeCommented:
Hi, Erik.

Welcome to EE.  Is the script moving any items at all or does it generate the error on the first item it processes?
0
fredfromnowonCommented:
BlueDevilFan.
Thanks for the warm welcome. I was hoping you might reply. It does nothing. Just generates the error. I am going to look at make sure he is on the same service pack that I am on (it works fine on my system).

Erik
0
David LeeCommented:
Ok.  I'll be here when you're ready to move on.
0
fredfromnowonCommented:
BlueDevilFan - just wanted to touch base and let you know I have not had a chance to work on this guy's computer. He is a Sr VP so I have to work around his schedule.
0
David LeeCommented:
fredfromnowon - In understand.  Thanks for the update.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.