macro unable to delete e-mails automatically

I have written a macro (based on code that BlueDevilFan supplied here) to automatically empty the deleted items folder. However it works on a machine with Outlook 2007 installed, it wouldn't work on a machine that had Outlook 2003 installed.

With 2003 I discovered that it would only delete some items (say 1 or 2). Nothing further happened.

However when I ran the code in the VBE editor, by pressing F5 I got a message stating that outlook was unable to remove the file, or that it didn't exist or that I didn't have permission.

When i did a MSGBOX in the routine to return (via Count) the number of items, the right number of items were coming up.

Has anybody else experienced this problem or can they suggest a solution ? Thanks

Sub Clean_Up_Outlook()
'empty the junk e-mail folder
Call Empty_Folder("Junk E-mail")
'empty the deleted items folder
Call Empty_Folder("Deleted Items")
End Sub
Sub Empty_Folder(Folder_Name As String)
    Dim olkFolder As Outlook.MAPIFolder, _
        olkItem As Object, _
        intIndex As Integer
    Set olkFolder = Session.GetDefaultFolder(olFolderInbox).Parent.Folders(Folder_Name)
    For intIndex = olkFolder.Items.Count To 1 Step -1
        Set olkItem = olkFolder.Items.Item(intIndex)
    Set olkFolder = Nothing
    Set olkItem = Nothing
End Sub

Open in new window

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.

David LeeCommented:
Hi, KapTheHat.

I just ran the code on my copy of Outlook 2003.  It ran without a problem.  What line of code gave the error you received?
KapTheHatAuthor Commented:
i think it was line 22. However it gave a message box - but no debug option. thanks

David LeeCommented:
Try using the debugger to step through the code.  Are you familiar with how to do that?
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!

KapTheHatAuthor Commented:
yes I am familar. I will try that. the wierd thing is when I delete the objects manually, they do delete. Thanks

KapTheHatAuthor Commented:
it appears that there is a problem with certain set ups of Windows XP. Microsoft have released a hotfix. Thanks for all your help.


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
David LeeCommented:
You're welcome.
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

From novice to tech pro — start learning today.