Archive only 'Read e-mails'

  • Thread starter Thread starter Nabeel
  • Start date Start date
N

Nabeel

Hi,


Is there a way to defined AutoArchiving to only archive read emails
older than a certain period?
 
Nabeel said:
Is there a way to defined AutoArchiving to only archive read emails
older than a certain period?

That's exactly what AutoArchive does, with one exception: it doesn't
distinguish between read and unread. Any message whose modification date is
older than the archive date you choose will be archived.
 
One workaround would be to write some VBA code to set the "Do Not
Archive" flag on Read emails, then when you click on File>Archive,
uncheck "Include items with "Do not AutoArchive" checked." so those
emails would not be moved to archive.


HTH,
JP
 
I think you meant setting the 'Do Not archive' on 'unread emails'
and then there would be another piece of code to fire on the event
when the msg turns to 'read'.

anyone who can help with the code?
 
You may want to post your question in microsoft.­public.­outlook.­
program_vba.

To get you started, you would need to check the ItemChange event for
your Inbox and see if the "Read" property of an email changes. If it
does, set the flag so it won't be archived. This code is a bit crude
so hopefully someone else will be able to refine it for you.

For example:

Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub Items_ItemChange(ByVal Item As Object)
If (Item.Class = olMail) And (Item.UnRead = False) Then
On Error Resume Next
' Msgbox "Setting do not archive flag now"
Item.NoAging = True
On Error Goto 0
End if
End Sub


HTH,
JP
 
JP said:
One workaround would be to write some VBA code to set the "Do Not
Archive" flag on Read emails, then when you click on File>Archive,
uncheck "Include items with "Do not AutoArchive" checked." so those
emails would not be moved to archive.

But he wants to archive the read mail. He doesn't want to archive unread
mail. The VBA code should add the flag to unread items, not read items.
The problem I see with that, though, it that it would be all too esy to
forget to reenable archiving on the items as they become read. He's wind up
with nothing being archived as messages aged.
 
Sorry that should be

Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim objNS As Outlook.NameSpace
Set objNS = Application.GetNamespace("MAPI")
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub Items_ItemChange(ByVal Item As Object)
If (Item.Class = olMail) And (Item.UnRead = False) Then
On Error Resume Next
' Msgbox "Setting do not archive flag now"
Item.NoAging = True
On Error Goto 0
End if
End Sub
 
Apparently today is my day to repost code over and over! :) I think
the double negatives are throwing me off. Thank you Brian, here is the
revised (again) code. I do agree with you and suggest something better
to the OP, like posting to the other group (or not leaving emails
unread <grin>).

But as long as the emails are read from the Inbox, wouldn't it trigger
this code and (eventually) get the msg archived?


Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim objNS As Outlook.NameSpace
Set objNS = Application.GetNamespace("MAPI")
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub Items_ItemChange(ByVal Item As Object)
If (Item.Class = olMail) And (Item.UnRead = False) Then
On Error Resume Next
' Msgbox "Setting do not archive flag now"
Item.NoAging = False
Else
Item.NoAging = True
On Error Goto 0
End if
End Sub


--JP
 
Back
Top