Importance: Normal v. None

B

Bongo

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
 
B

Bongo

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 . . .
 
B

Bongo

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.
 
B

Bongo

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.
 
B

Bongo

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!
 
M

Michael Bauer

Bongo, what do you mean by "crashing out", do you get an error (at least
after commenting out the OnError statement)?
 
B

Bongo

Sorry to be unclear. Prior to using the ItemAdd event handler (which seems to
be bug free) I used the following two routines as scripts to run from the
Rules Wizard on arrival of new mail:

Sub SetImportanceRuleMessage(Item As Outlook.MailItem)
On Error GoTo ErrorHandler
If Item.Importance <> olImportanceHigh Then
Item.Importance = olImportanceNormal
Item.Save
End If
Exit Sub
ErrorHandler:
MsgBox (Err.Number & " " & Err.Description & " " & Err.Source)
End Sub

Sub SetImportanceRuleReport(Item As Outlook.ReportItem)
On Error GoTo ErrorHandler
If Item.Importance <> olImportanceHigh Then
Item.Importance = olImportanceNormal
Item.Save
End If
Exit Sub
ErrorHandler:
MsgBox (Err.Number & " " & Err.Description & " " & Err.Source)
End Sub

The rules were only run upon the arrival of the respective message types
(based on Rules Wizard criteria). [As an aside, I'll mention that in order to
assign any Sub as a script in Rules Wizard the argument type needs to be
Outlook.MailItem, so you need to change the argument type *after* assigning
the rule.)

Annoyingly frequently, the rule would break (bringing up a Rules
Wizard-generated error window) and the rule (a) would not apply to the
current message; and (b) would be disactivated. The error handler in the Sub
would not be activated as far as I could tell. I was completely unable to
determine the source of the problem, which occurred roughly equally freqently
for the message script as for the receipt script.

Hence the switch to the ItemAdd handler, which is called by more normal
parts of the system (I think the problem before was with Rules Wizard). Since
changing over, I've had no problems (but would be very interested in anyone's
insight into why the Rules Wizard way had so many problems).

Tx & rgds
 
M

Michael Bauer

Bongo,

if the wizzard expects a MailItem then you can´t change that after
assigning.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook


Bongo said:
Sorry to be unclear. Prior to using the ItemAdd event handler (which seems to
be bug free) I used the following two routines as scripts to run from the
Rules Wizard on arrival of new mail:

Sub SetImportanceRuleMessage(Item As Outlook.MailItem)
On Error GoTo ErrorHandler
If Item.Importance <> olImportanceHigh Then
Item.Importance = olImportanceNormal
Item.Save
End If
Exit Sub
ErrorHandler:
MsgBox (Err.Number & " " & Err.Description & " " & Err.Source)
End Sub

Sub SetImportanceRuleReport(Item As Outlook.ReportItem)
On Error GoTo ErrorHandler
If Item.Importance <> olImportanceHigh Then
Item.Importance = olImportanceNormal
Item.Save
End If
Exit Sub
ErrorHandler:
MsgBox (Err.Number & " " & Err.Description & " " & Err.Source)
End Sub

The rules were only run upon the arrival of the respective message types
(based on Rules Wizard criteria). [As an aside, I'll mention that in order to
assign any Sub as a script in Rules Wizard the argument type needs to be
Outlook.MailItem, so you need to change the argument type *after* assigning
the rule.)

Annoyingly frequently, the rule would break (bringing up a Rules
Wizard-generated error window) and the rule (a) would not apply to the
current message; and (b) would be disactivated. The error handler in the Sub
would not be activated as far as I could tell. I was completely unable to
determine the source of the problem, which occurred roughly equally freqently
for the message script as for the receipt script.

Hence the switch to the ItemAdd handler, which is called by more normal
parts of the system (I think the problem before was with Rules Wizard). Since
changing over, I've had no problems (but would be very interested in anyone's
insight into why the Rules Wizard way had so many problems).

Tx & rgds

Michael Bauer said:
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


for
different scripts
and follwing
event incoming
messages day
(still which it
pukes; the
Rules on
messages I
understood but I
haven't setting
from as
ones with
the Importance
to alternatively,
all same
to conception of
the
 
B

Bongo

Actually, it worked . . . each rule (the one for the mail items and the one
for the report items) crashed with similar frequency.

Michael Bauer said:
Bongo,

if the wizzard expects a MailItem then you can´t change that after
assigning.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook


Bongo said:
Sorry to be unclear. Prior to using the ItemAdd event handler (which seems to
be bug free) I used the following two routines as scripts to run from the
Rules Wizard on arrival of new mail:

Sub SetImportanceRuleMessage(Item As Outlook.MailItem)
On Error GoTo ErrorHandler
If Item.Importance <> olImportanceHigh Then
Item.Importance = olImportanceNormal
Item.Save
End If
Exit Sub
ErrorHandler:
MsgBox (Err.Number & " " & Err.Description & " " & Err.Source)
End Sub

Sub SetImportanceRuleReport(Item As Outlook.ReportItem)
On Error GoTo ErrorHandler
If Item.Importance <> olImportanceHigh Then
Item.Importance = olImportanceNormal
Item.Save
End If
Exit Sub
ErrorHandler:
MsgBox (Err.Number & " " & Err.Description & " " & Err.Source)
End Sub

The rules were only run upon the arrival of the respective message types
(based on Rules Wizard criteria). [As an aside, I'll mention that in order to
assign any Sub as a script in Rules Wizard the argument type needs to be
Outlook.MailItem, so you need to change the argument type *after* assigning
the rule.)

Annoyingly frequently, the rule would break (bringing up a Rules
Wizard-generated error window) and the rule (a) would not apply to the
current message; and (b) would be disactivated. The error handler in the Sub
would not be activated as far as I could tell. I was completely unable to
determine the source of the problem, which occurred roughly equally freqently
for the message script as for the receipt script.

Hence the switch to the ItemAdd handler, which is called by more normal
parts of the system (I think the problem before was with Rules Wizard). Since
changing over, I've had no problems (but would be very interested in anyone's
insight into why the Rules Wizard way had so many problems).

Tx & rgds

Michael Bauer said:
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
 
M

Michael Bauer

Actually, it worked . . . each rule (the one for the mail items and
the one
for the report items) crashed with similar frequency.

Yes, obvioulsy it works like a charm :))
 
B

Bongo

The rule for messages was:

Apply this rule after the message arrives
uses the ‘Encrypted Message’ or ‘Message’ form
and on this machine only
run JB_Outlook.ThisOutlookSession.SetImportanceRuleMessage

where the script refers to:

Sub SetImportanceRuleMessage(Item As Outlook.MailItem)
On Error GoTo ErrorHandler
If Item.Importance <> olImportanceHigh Then
Item.Importance = olImportanceNormal
Item.Save
End If
Exit Sub
ErrorHandler:
MsgBox (Err.Number & " " & Err.Description & " " & Err.Source)
End Sub

If you have any idea why the rule would break _seemingly without ever
calling the procedure_ (the error handler isn't called, debug.print
previously put at top of sub never executed, etc.), I'd be very interested.

Thoughts?
 
M

Michael Bauer

Is something "crashing", whatever that means for you, or won´t the event
executed at all? I´m a little confused.

Did you check other rules? Maybe there´s one executed before and ending
with "Don´t use more rules" (don´t know the correct translation).
 
B

Bongo

Hi Michael,

I have attempted to send you a picture of the dialog and some additional
informaiton to your e-mail. If you haven't received it, please let me know
here.

Rgds
Bongo
 
M

Michael Bauer

Hi,

if there was an e-mail with attachments then I´ve deleted it - and I
would do again. Please post all infos here, maybe some others do have
additional ideas.
 

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