Bongo, what do you mean by "crashing out", do you get an error (at least
after commenting out the OnError statement)?
--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
No matter what I did (error handlers, specifying separate rules for
different
message types, I couldn't get it to stop crashing out on the scripts
and
disabling the rules.
Starting with Sue Mosher's code at
http://www.outlookcode.com/d/code/quarexe.htm, I added the follwing
event
handler to ThisOutlookSession (note: this intentionally sets
Importance to
Normal for messages with no Importance as well as Low Importance):
Private WithEvents olInboxItems As Items
Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set objNS = Nothing
End Sub
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
On Error Resume Next
Debug.Print "In"
If Item.Class = olMail Or Item.Class = olReport Then
If Item.Importance <> olImportanceHigh Then
Item.Importance = olImportanceNormal
Item.Save
End If
End If
On Error GoTo 0
End Sub
Thanks Sue!
:
1) Go to the Outlook's Visual Basic Editor (Tools:Macros:Visual
Basic Editor).
2) Add a module to VbaProject.otm if there isn't one.
3) Paste the funcion in from the previous posting.
4) Save the project and close the Visual Basic Editor window.
5) In the Rules Wizard, add a new rule applicable to all incoming
messages
of type "run a script".
6) Select the script you just created.
Note that at least in my case, the rule pukes at least once a day
(still
can't figure out why) and (a) doesn't run on the message on which it
pukes;
and (b) is disabled for future messages. To deal with this, just
turn it on
again in the Rules Wizard, and apply it manually (again, from the
Rules
Wizard) on unread messages to get the importance set correctly on
messages
received after the rule was disabled (or do it manually). I wish I
understood
what was causing the rule to generate an (untrappable) error, but I
haven't
been able to figure it out yet.
:
How do I implement these instructions into Outlook?
Bongo wrote:
And here's the solution to the second problem (again, converting
items that
either have no Importance set, or have Low Importance to
Normal):
Sub SetImportanceRule(Item As Outlook.MailItem)
If Item.Importance <> olImportanceHigh Then
Item.Importance = olImportanceNormal
Item.Save
End If
End Sub
This will then show up as an available script in the rules
wizard,
which
should be applied to all incoming mail.
:
Here's a solution to the first one (cribbed the object setting
from
another
posting). I convert Low Importance items to Normal as well as
ones
with unset
Importance:
Public Sub grungeimp()
Dim objApp As Outlook.Application
Dim objNameSpace As Outlook.NameSpace
Dim objMAPIFolder As Outlook.MAPIFolder
Dim objMailItem As Outlook.MailItem
Dim lngOldMailCounter As Long
Dim lngNewMailCounter As Long
Set objApp = Outlook.Application
Set objNameSpace = objApp.GetNamespace(Type:="MAPI")
Set objMAPIFolder =
objNameSpace.Folders(4).Folders("testy")
' use whatever folder you want, for exmaple
objNameSpace.GetDefaultFolder(FolderType:=olFolderInbox)
For Each objMailItem In objMAPIFolder.Items
Debug.Print objMailItem.Importance & " " & i
If objMailItem.Importance <> olImportanceHigh Then
objMailItem.Importance = olImportanceNormal
objMailItem.Save
End If
i = i + 1
Next objMailItem
End Sub
Next, if anyone can give me a pointer as to how to work with
the
current
incoming message when using a rule on incoming messages . .. .
:
For some reason (possibly my POP server), incoming mail
comes
variously with
Importance set to Normal and not set at all. Since I sort my
inbox by
Importance, it's pretty annoying to have the unset ones
filter to
the bottom.
I'd like to take a crack at the following two programmatic
solutions (both
necessary):
1) a sript to be run on any folder that sets the Importance
to
"Normal" for
all items that have no Importance status (or alternatively,
all
items that
are neither "High" nor "Low" Importance); and/or
2) a script to be run from the rules wizard to do the same
to
incoming
messages.
I'm a decent Excel VBA programmer, but have no conception of
the
Outlook
object model or how to even start to attack this . . .
anyone
willing to
point me in the right direction?
Tx & rgds