Mark junk items as unread

P

Philip Brown

Hello,

I posted a request several days ago for help to know how
to mark items moved to a junk folder as read. Several
similar requests have been posted to the list without any
response.

Since then I've figured it out and figured I'd share it
for others searching for similar help. The following
code does the trick:

Public WithEvents myOlItems As Outlook.Items
Public Sub Application_Startup()
Dim objNS As NameSpace
Dim objInbox As MAPIFolder
' Reference the items in the Inbox. Because myOlItems
' is declared "WithEvents" the ItemAdd event will fire
' below.
Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.Folders.Item("Personal Folders")
Set myOlItems = objInbox.Folders("Junk E-Mail").Items
End Sub
Public Sub myOlItems_ItemAdd(ByVal Item As Object)

' Verify item is a mailitem
If TypeName(Item) = "MailItem" Then
With Item
.UnRead = False
.Save
End With
End If
End Sub
 
R

Renae Lindsay

I have the same problem as you, but I don't know how to program Outlook2000
to use your code. Can you explain? Thanks
 
P

Philip Brown

Hi, Renae,

Two options:
#1
In Outlook type ALT+F11, double-click Project1, double-
click Microsoft Outlook Objects, double-click
ThisOutlookSession. Paste the code in this window, save
the project, and you're through. Close out the Microsoft
Visual Basic window

#2
Download Spambayes from Spambayes.com and install. This
automatically sorts email and has the option to mark Junk
mail as read.
 
B

blaze

Excellent post Philip. I've been looking for this for months. I know
VBA but not a lot of the Outlook specific syntax, so this saved me a
learning experience I would not have utilized for other things.

Thanks again.
 
G

Guest

THanks Philip. I tried to do the same thing (I thought)
and got a run-time error saying the Property was Read
Only. Not sure what I was doing but adding MyItem.UnRead
= False works. Thanks again!
 
R

rpfields

Greetings! This works great for one folder? How could one apply thi
to multiple folders?

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top