Hi,
I have processes that automate outgoing emails. These can clog my sent mail folder and at some point reach a limit.
I need a good process that would instruct outlook after each mail item is sent, (with a specific character value in the subject or specific sender as I use the 'send as' feature), to then move the sent mail out of the SENT folder and into the Deleted folder.
I can find no way to set this up with the standard rules wizard so a friend helped me write some VBA.
Here is what I am doing now, however this apparently just stops working daily....
Basically if I reboot the computer or shut down and restart Outlook this will for for the day or the afternoon, but then stops later...
Any advice on a more reliable method or a way to auto trigger the Application_Startup throughout the day or something would be appreciated.
'-------Option Explicit
Dim WithEvents objInbox As Outlook.Items
Dim AppNS As NameSpace
Private WithEvents olSentItems As Items
Private WithEvents olSent As Folders
'---Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set olSentItems = objNS.GetDefaultFolder(olFolderSentMail).Items
'Set olDeletedItems = objNS.GetDefaultFolder(olFolderDeletedItems).Items
Set objNS = Nothing
End Sub
'-----Private Sub olSentItems_ItemAdd(ByVal Item As Object)
Dim objPF As MAPIFolder
Dim objIC As MAPIFolder
Dim objSent As MAPIFolder
Dim objDestination As MAPIFolder
Set AppNS = Application.GetNamespace("MAPI")
If Item.Class = olMail And InStr(1, Trim(Item.Subject), "***", vbTextCompare) > 0 _
Or InStr(1, Trim(Item.Subject), "TBD", vbTextCompare) > 0 _
Then
Item.Delete
'ElseIf Item.Class = olMail And InStr(1, Trim(Item.Subject), "TBD", vbTextCompare) > 0 _
'Then
'Item.Delete
End If
End Sub
'-----------Regards,
Nick
I have processes that automate outgoing emails. These can clog my sent mail folder and at some point reach a limit.
I need a good process that would instruct outlook after each mail item is sent, (with a specific character value in the subject or specific sender as I use the 'send as' feature), to then move the sent mail out of the SENT folder and into the Deleted folder.
I can find no way to set this up with the standard rules wizard so a friend helped me write some VBA.
Here is what I am doing now, however this apparently just stops working daily....
Basically if I reboot the computer or shut down and restart Outlook this will for for the day or the afternoon, but then stops later...
Any advice on a more reliable method or a way to auto trigger the Application_Startup throughout the day or something would be appreciated.
'-------Option Explicit
Dim WithEvents objInbox As Outlook.Items
Dim AppNS As NameSpace
Private WithEvents olSentItems As Items
Private WithEvents olSent As Folders
'---Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set olSentItems = objNS.GetDefaultFolder(olFolderSentMail).Items
'Set olDeletedItems = objNS.GetDefaultFolder(olFolderDeletedItems).Items
Set objNS = Nothing
End Sub
'-----Private Sub olSentItems_ItemAdd(ByVal Item As Object)
Dim objPF As MAPIFolder
Dim objIC As MAPIFolder
Dim objSent As MAPIFolder
Dim objDestination As MAPIFolder
Set AppNS = Application.GetNamespace("MAPI")
If Item.Class = olMail And InStr(1, Trim(Item.Subject), "***", vbTextCompare) > 0 _
Or InStr(1, Trim(Item.Subject), "TBD", vbTextCompare) > 0 _
Then
Item.Delete
'ElseIf Item.Class = olMail And InStr(1, Trim(Item.Subject), "TBD", vbTextCompare) > 0 _
'Then
'Item.Delete
End If
End Sub
'-----------Regards,
Nick