Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Handling Outlook 2003 Events
#1
Is it possible to handle Outlook 2003 VBA events in QM?
When a message is sent (arrives in the Outlook Sent Items folder) I would like QM to print the message and move it to one of several mail folders.

This page, http://www.outlookcode.com/article.aspx?id=62, discusses some options for processing messages when they arrive in Outlook, including "Method 2: Using the Items.ItemAdd event", which could be used with the Sent Items folder.

Could the example code (copied below) be implemented in QM so that QM could handle the ItemAdd event when new items arrive in the Inbox or Sent Items folders?
Thanks in advance,
John

Sample code for: Method 2: Using the Items.ItemAdd event
Code:
Copy      Help
Option Explicit

Private WithEvents olInboxItems As Items

Private Sub Application_Startup()
  Dim objNS As NameSpace
  Set objNS = Application.Session
  ' instantiate objects declared WithEvents
  Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
  Set objNS = Nothing
End Sub

Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
  On Error Resume Next
  Item.BodyFormat = olFormatPlain
  Item.Save
  Set Item = Nothing
End Sub
#2
you can use the VB scripting engine to execute this exact code if you want. I use QM to modify vb code with a variable and then execute the vb code. It works really well.

I guess the trick would be catching the new item flag from Outlook.
An old blog on QM coding and automation.

The Macro Hook
#3
Function outlook_inbox_trigger
Code:
Copy      Help
;/exe 1
typelib Outlook {00062FFF-0000-0000-C000-000000000046} 9.2

Outlook.Application a._getactive
Outlook.NameSpace ns=a.Session
Outlook.Items items=ns.GetDefaultFolder(olFolderInbox).Items
items._setevents("items_ItemsEvents")

;wait until outlook exits
a._setevents("a_ApplicationEvents_11")
opt waitmsg 1
int- t_quit
rep() 1; if(t_quit) break


Attached Files
.qml   outlook inbox trigger.qml (Size: 1.3 KB / Downloads: 475)
#4
here's some mods I made to get this to work for me.
Function items_ItemAdd
Code:
Copy      Help
function IDispatch'item ;;Outlook._Items'items
str from to subj body
str+ lml_behind
;out "outlook item added"
;out item.BodyFormat

typelib Outlook
Outlook.MailItem mi=item

subj=item.Subject
from=item.Sender
to=item.To


err+ out _error.description
An old blog on QM coding and automation.

The Macro Hook
#5
Here's another setting for putting in a 'reminder' for a certain date/time.

Macro Send Email Via Outlook
Code:
Copy      Help
email.FlagDueBy="10/26/2012 12:00 pm"
An old blog on QM coding and automation.

The Macro Hook
#6
WOW!!!! Quick cultural note: in America when we think something is really cool, we say, "This is the best thing since sliced bread!!". a popular alternative is "...since canned beer!!". I don't know what was so amazing before sliced bread that they compared everything to, maybe aqueducts or bronze maybe.

This Inbox thing may very well be the coolest thing since the "Convert to function"!!

Here's what I'm doing. I get a bunch of emails in from a SQL Server monitoring process telling me if something is running. it is useful but not for me usually but if it is running a loooooong time, it is useful. the problem is that Outlook won't delete a message based on a value in the message being lower that a certain value.

So, I have QM watching the Inbox. When I get an email from 'X', it grabs the entire message and does the below to it.

Function items_ItemAdd
Code:
Copy      Help
findrx(body "has been executing for ([\d\.]+) minutes" 0 1 _s 1)

Now it takes _s and does this

Function items_ItemAdd
Code:
Copy      Help
,_i=val(_s)
,if _i<30
,,mi.Delete

so, it's not in my Inbox AND doesn't even put up a 'New Message' notification so I'm not bothered at all!!!!

Totally cooler than the new editor, or the OnScreenDisplay, or even the OnScreenDisplay with round corners. Ok, maybe not as cool as the multiple keyboard and mouse thing, I'll admit, but AT LEAST as cool as that!
An old blog on QM coding and automation.

The Macro Hook


Forum Jump:


Users browsing this thread: 1 Guest(s)