We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Delete emails from Inbox

Mighty_Ed
Mighty_Ed asked
on
Medium Priority
3,509 Views
Last Modified: 2010-02-09
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
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2008

Commented:
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!

Commented:
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.

Author

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
CERTIFIED EXPERT
Top Expert 2010

Commented:
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!

Author

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
CERTIFIED EXPERT
Top Expert 2010
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
any way in which I can avoid the message to choose to run or not the macros?
CERTIFIED EXPERT
Top Expert 2010

Commented:
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.

Author

Commented:
Thanks everything worked perfectly and trasnparent for the user.
You rock. Please let me know if you received the 600 points
CERTIFIED EXPERT
Top Expert 2010

Commented:
Thanks!  You're welcome.  I don't know about 600 points.  I received 1000 points (250 * 4 for the A).

Author

Commented:
cool
so we are done !!!
thanks again

Commented:
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?
CERTIFIED EXPERT
Top Expert 2010

Commented:
Hi, ibcjapan.

What line are you getting the error on?  Did you follow the directions exactly?
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
CERTIFIED EXPERT
Top Expert 2010

Commented:
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?
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
CERTIFIED EXPERT
Top Expert 2010

Commented:
Ok.  I'll be here when you're ready to move on.
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.
CERTIFIED EXPERT
Top Expert 2010

Commented:
fredfromnowon - In understand.  Thanks for the update.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.