Link to home
Start Free TrialLog in
Avatar of KapTheHat
KapTheHat

asked on

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

Kaps
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)
        olkItem.Delete
    Next
    Set olkFolder = Nothing
    Set olkItem = Nothing
 
End Sub

Open in new window

Avatar of David Lee
David Lee
Flag of United States of America image

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?
Avatar of KapTheHat
KapTheHat

ASKER

i think it was line 22. However it gave a message box - but no debug option. thanks

Kaps
Try using the debugger to step through the code.  Are you familiar with how to do that?
yes I am familar. I will try that. the wierd thing is when I delete the objects manually, they do delete. Thanks

Kaps
ASKER CERTIFIED SOLUTION
Avatar of KapTheHat
KapTheHat

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You're welcome.