Paul Banbury
New Member
- Outlook version
- Outlook 2013 64 bit
- Email Account
- Exchange Server
I am looking for a macro to run a script to delete emails from an inbox for a ghost user, we have an account that is used to send a PDF form into i have created the macros with the help of others to move the attached PDF to a server folder and for the user that require the forms to get a message to say that they have received a new form, the reason we have done this is to keep the size of the mail box under control but im struggling with a macro to delete them say after 12 hours or even a day i would like to try both. I am using Outlook 2013 and this is what i have so far but it doea not seem to work, i was given the code by a collegue and advised to just adjust the days to what i need i have tried 1 and .5 for 12 hours.
Public Sub RemoveEmail5(Item As Outlook.MailItem)
Dim olSession As Outlook.Application, olNamespace As NameSpace
Dim olInbox As Outlook.MAPIFolder
Dim i As Integer
Set olSession = New Outlook.Application
Set olNamespace = olSession.GetNamespace("MAPI")
Set olInbox = olNamespace.GetDefaultFolder(olFolderInbox)
Set Delete_Items = olInbox.Items
For i = Delete_Items.Count To 1 Step -1
If TypeName(Delete_Items.Item(i)) = "MailItem" Then
If DateDiff("d", Now, Delete_Items.Item(i).ReceivedTime) > 0.5 Then Delete_Items.Item(i).Delete
End If
Next
Set olSession = Nothing
Set olNamespace = Nothing
Set olInbox = Nothing
End Sub
Public Sub RemoveEmail5(Item As Outlook.MailItem)
Dim olSession As Outlook.Application, olNamespace As NameSpace
Dim olInbox As Outlook.MAPIFolder
Dim i As Integer
Set olSession = New Outlook.Application
Set olNamespace = olSession.GetNamespace("MAPI")
Set olInbox = olNamespace.GetDefaultFolder(olFolderInbox)
Set Delete_Items = olInbox.Items
For i = Delete_Items.Count To 1 Step -1
If TypeName(Delete_Items.Item(i)) = "MailItem" Then
If DateDiff("d", Now, Delete_Items.Item(i).ReceivedTime) > 0.5 Then Delete_Items.Item(i).Delete
End If
Next
Set olSession = Nothing
Set olNamespace = Nothing
Set olInbox = Nothing
End Sub