Automatic Copy of Only Read Mail?

  • Thread starter Thread starter Don Miller
  • Start date Start date
D

Don Miller

I used to use a rule to copy everything that comes to my inbox and place it
in a personal folder called "Mail Archive". Now with all of the junk mail
some of which doesn't get caught by rules, and also using a spam guard like
SPAMBayes that deletes spam but apparently does so after my rule runs, I end
up with junkmail and spam in the archive folder that I have to manually
delete. So, I turned off the rule and now I just manually copy "good" email
to the archive where before it was automatic and I didn't have to worry
about making sure the mail was copied.

Is there a way with VBA that Outlook 2000 would automatically copy an email
to a personal folder but only after I actually read it (I don't read spam
and I don't use Preview Panes)?

Thanks for any tips with VBA or otherwise to archive my mail without junk or
spam.
 
I wanted to play with VBA and the VBA code below works when I assign it to a
macro button. But I wanted to automate it (without having to press a button)
with a VBA event (code way below) but it doesn't seem to do anything, and no
errors.


Sub ArchiveMail()
Dim objApp As Application
Set objApp = CreateObject("Outlook.Application")

Dim objItem As Object

Select Case objApp.ActiveWindow.Class
Case olExplorer
Set objSel = objApp.ActiveExplorer.Selection
If objSel.Count > 0 Then
Set objItem = objSel.Item(1)
End If
Case olInspector
Set objItem = objApp.ActiveInspector.CurrentItem
Case Else
'can 't handle any other kind of window
End Select

If objItem.Class = olMail Then
Dim myNameSpace As NameSpace
Dim myFolders As Folders

Set myNameSpace = objApp.GetNamespace("MAPI")
Set myFolders = myNameSpace.Folders
Set myArchiveFolder = myFolders.Item("Personal
Folders").Folders("Inbox").Folders("Mail Archive")
Set myCopiedItem = objItem.Copy
myCopiedItem.UnRead = False
myCopiedItem.Move myArchiveFolder
End If
End Sub

In ThisOutlookSession:

Dim WithEvents myMailItems As Outlook.MailItem

Private Sub Application_Startup()
Set myMailItems =
Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub myMailItems_Read()
If myMailItems.Class = olMail Then

Dim myOlApp As Application
Set myOlApp = CreateObject("Outlook.Application")

Dim myNameSpace As NameSpace
Dim myFolders As Folders

Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolders = myNameSpace.Folders
Set myArchiveFolder = myFolders.Item("Personal
Folders").Folders("Inbox").Folders("Mail Archive")
Set myCopiedItem = myMailItems.Copy
myCopiedItem.UnRead = False
myCopiedItem.Move myArchiveFolder
End If
End Sub


Diane Poremsky said:
Either use VBA or Exlife (www.ornic.com) to create rules and run them when
you want to clean out the messages.

--
Diane Poremsky [MVP - Outlook]
Author, Teach Yourself Outlook 2003 in 24 Hours
Coauthor, OneNote 2003 for Windows (Visual QuickStart Guide)
Author, Google and Other Search Engines (Visual QuickStart Guide)





Don Miller said:
I used to use a rule to copy everything that comes to my inbox and place it
in a personal folder called "Mail Archive". Now with all of the junk mail
some of which doesn't get caught by rules, and also using a spam guard
like
SPAMBayes that deletes spam but apparently does so after my rule runs, I
end
up with junkmail and spam in the archive folder that I have to manually
delete. So, I turned off the rule and now I just manually copy "good"
email
to the archive where before it was automatic and I didn't have to worry
about making sure the mail was copied.

Is there a way with VBA that Outlook 2000 would automatically copy an
email
to a personal folder but only after I actually read it (I don't read spam
and I don't use Preview Panes)?

Thanks for any tips with VBA or otherwise to archive my mail without junk
or
spam.
 
Because Junk mail filters run last, I think the best way is to run it
manually every few hours or days anyway...

--


Don Miller said:
I wanted to play with VBA and the VBA code below works when I assign it to
a
macro button. But I wanted to automate it (without having to press a
button)
with a VBA event (code way below) but it doesn't seem to do anything, and
no
errors.


Sub ArchiveMail()
Dim objApp As Application
Set objApp = CreateObject("Outlook.Application")

Dim objItem As Object

Select Case objApp.ActiveWindow.Class
Case olExplorer
Set objSel = objApp.ActiveExplorer.Selection
If objSel.Count > 0 Then
Set objItem = objSel.Item(1)
End If
Case olInspector
Set objItem = objApp.ActiveInspector.CurrentItem
Case Else
'can 't handle any other kind of window
End Select

If objItem.Class = olMail Then
Dim myNameSpace As NameSpace
Dim myFolders As Folders

Set myNameSpace = objApp.GetNamespace("MAPI")
Set myFolders = myNameSpace.Folders
Set myArchiveFolder = myFolders.Item("Personal
Folders").Folders("Inbox").Folders("Mail Archive")
Set myCopiedItem = objItem.Copy
myCopiedItem.UnRead = False
myCopiedItem.Move myArchiveFolder
End If
End Sub

In ThisOutlookSession:

Dim WithEvents myMailItems As Outlook.MailItem

Private Sub Application_Startup()
Set myMailItems =
Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub myMailItems_Read()
If myMailItems.Class = olMail Then

Dim myOlApp As Application
Set myOlApp = CreateObject("Outlook.Application")

Dim myNameSpace As NameSpace
Dim myFolders As Folders

Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolders = myNameSpace.Folders
Set myArchiveFolder = myFolders.Item("Personal
Folders").Folders("Inbox").Folders("Mail Archive")
Set myCopiedItem = myMailItems.Copy
myCopiedItem.UnRead = False
myCopiedItem.Move myArchiveFolder
End If
End Sub


Diane Poremsky said:
Either use VBA or Exlife (www.ornic.com) to create rules and run them
when
you want to clean out the messages.

--
Diane Poremsky [MVP - Outlook]
Author, Teach Yourself Outlook 2003 in 24 Hours
Coauthor, OneNote 2003 for Windows (Visual QuickStart Guide)
Author, Google and Other Search Engines (Visual QuickStart Guide)





Don Miller said:
I used to use a rule to copy everything that comes to my inbox and place it
in a personal folder called "Mail Archive". Now with all of the junk mail
some of which doesn't get caught by rules, and also using a spam guard
like
SPAMBayes that deletes spam but apparently does so after my rule runs,
I
end
up with junkmail and spam in the archive folder that I have to manually
delete. So, I turned off the rule and now I just manually copy "good"
email
to the archive where before it was automatic and I didn't have to worry
about making sure the mail was copied.

Is there a way with VBA that Outlook 2000 would automatically copy an
email
to a personal folder but only after I actually read it (I don't read spam
and I don't use Preview Panes)?

Thanks for any tips with VBA or otherwise to archive my mail without junk
or
spam.
 
Back
Top