Re: Importance: Normal v. None



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" wrote:

> 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
>
>
> "Bongo" <Bongo@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:F3C89DA8-E55E-4E95-AA9C-B8563F5542AA@xxxxxxxxxxxxxxxx
> > 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!
> >
> > "Bongo" wrote:
> >
> > > 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.
> > >
> > > "tattooedgroove" wrote:
> > >
> > > > 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.
> > > > > "Bongo" wrote:
> > > > >
> > > > > > 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 . . .
> > > > > >
> > > > > > "Bongo" wrote:
> > > > > >
> > > > > > > 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
> > > > > > >
> > > >
> > > >
>
>
.



Relevant Pages

  • Re: Importance: Normal v. None
    ... disabling the rules. ... Private Sub Application_Startup ... > 6) Select the script you just created. ... > again in the Rules Wizard, and apply it manually (again, from the Rules ...
    (microsoft.public.outlook.program_vba)
  • Re: Importance: Normal v. None
    ... >> Sub SetImportanceRuleMessage ... >> On Error GoTo ErrorHandler ... >> assign any Sub as a script in Rules Wizard the argument type needs to ... >> for the message script as for the receipt script. ...
    (microsoft.public.outlook.program_vba)
  • Re: Data Persistence Across Scripts?
    ... Rules Wizard, chose "Run a script" as one of the actions, and clicked on the ... Sub MyRules ... The rules look> fine when Application_Startup ends, but they're empty when> MyRules starts. ...
    (microsoft.public.outlook.program_vba)
  • Re: Importance: Normal v. None
    ... > Sub SetImportanceRuleMessage ... > On Error GoTo ErrorHandler ... > (based on Rules Wizard criteria). ... > for the message script as for the receipt script. ...
    (microsoft.public.outlook.program_vba)
  • VERY weird taint + Tk::Error + MIME::Head::get error
    ... sub build_parser { ... For some reason a taint error is being generated after the diebut _before_ Tk::Error is called and is handled by Tk::ErrorDialog. ... I have to use taint (it's not voluntary - the script is launched via a wrapper setuid to access a database password) and I have to use MIME::Entity et al. GUI's vanishing disgracefully is not really acceptable which is why I want to use a Tk::Error handler. ...
    (comp.lang.perl.tk)