
Contamos con un sistema automatizado que envía actualizaciones vía correo electrónico. Está bien y para mí es información útil. Preferiría ver solo la actualización más reciente y eliminar el resto. Es decir, dada la siguiente lista
Solo quiero que la versión seleccionada de la actualización 34022 permanezca en mi carpeta. He investigado las Reglas, pero nada parece encajar.
¿Hay alguna manera de eliminar (automáticamente) los que no quiero?
Respuesta1
Con algo de VBA. Siempre es una buena idea realizar pruebas exhaustivas cuando se trata de eliminar.
Private Sub Application_NewMail()
' In ThisOutlookSession module
' see Create Outlook Rules Programmatically
' http://msdn.microsoft.com/en-us/library/aa163981(v=office.10).aspx
Dim olApp As Outlook.Application
Dim olNs As Outlook.NameSpace
Dim olFld As Outlook.MAPIFolder
Dim objMail As Object
Set olApp = Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set olFld = olNs.GetDefaultFolder(olFolderInbox)
olFld.items.sort "Received", False
'Set objMail = olFld.items.GetFirst ' In Outlook 2003
Set objMail = olFld.items.GetLast ' In Outlook 2010
If TypeOf objMail Is MailItem Then
If objMail.SenderEmailAddress = "Found in DetermineSenderEmailAddress" And _
InStr(1, objMail.Subject, "Ticket:") Then
DeleteOldStatus objMail
End If
End If
Set objMail = Nothing
Set olFld = Nothing
Set olNs = Nothing
Set olApp = Nothing
End Sub
Sub DeleteOldStatus(objMail As MailItem)
Dim olFld As folder
Dim olNs As NameSpace
Dim olderMail As MailItem
Dim iDel As Long
Set olNs = Application.GetNamespace("MAPI")
Set olFld = olNs.GetDefaultFolder(olFolderInbox)
For iDel = olFld.items.Count To 1 Step -1
Set olderMail = olFld.items(iDel)
If olderMail.Subject = objMail.Subject Then
If olderMail.ReceivedTime < objMail.ReceivedTime Then
Debug.Print olderMail.Subject & " received " & olderMail.ReceivedTime & " should be deleted."
'olderMail.Delete ' Remove leading apostrophe to uncomment when ready
End If
End If
Next
Debug.Print "Done - " & objMail.Subject
End Sub
Sub DetermineSenderEmailAddress()
' open up an email then run
Dim currItem As MailItem
Set currItem = ActiveInspector.currentItem
' Copy the text from the immediate pane.
Debug.Print currItem.SenderEmailAddress
End Sub
Editor y ayuda de botones -http://www.slipstick.com/developer/how-to-use-outlooks-vba-editor/
La seguridad macro debe establecerse en media.
Botón de ayuda -http://www.howto-outlook.com/howto/macrobutton.htm
Editar: Se corrigió la línea InStr