PDA

View Full Version : Auto-email when task added



bnquinn
02-20-2009, 05:58 PM
Hi there.
I want to make Outlook send an email whenever a task is added.

in brief pseudo-code

if new task
send an email (using outlook of course)
endif

I know I need to trap an event but don't know which one. While I can do a lot with VBA in Excel & Access I never really got to grips with VBA in Outlook.

Can anyone give me a head start please?

Thanks, BQ.

Charlize
02-23-2009, 06:43 AM
Place every coding in the ThisOutlookSession. The code that follows here must be placed all the way up in your module.
'*** Handle taskevents - place this in thisoutlooksession
'*** in front of all the other codings
'NewTask is the task we want to handle
Public WithEvents NewTask As Outlook.TaskItem
Public WithEvents objinspectors As Outlook.Inspectors
'*** End of the handles
The next piece of coding needs to be placed in the Application_Quit section.
Private Sub Application_Quit()
'Don't copy the private sub application_quit. Only the code in between
'needs to be placed at the correct location.
Set objinspectors = Nothing
End Sub
This piece in the Application_Startup section
Private Sub Application_Startup()
'Don't copy the private sub application_startup. Only the code ...
Set objinspectors = Application.Inspectors
End Sub
This is a new piece of coding to trap 'objinspectors' ie. copy and paste in ThisOutlookSession.
Private Sub objinspectors_NewInspector(ByVal Inspector As Inspector)
Dim ocurrentitem As Object
Set ocurrentitem = Inspector.CurrentItem
If ocurrentitem.Class = 48 Then
'Here we put the current objectitem in NewTask (task item)
Set NewTask = ocurrentitem
End If
End Sub
And now the two pieces that deal with the creating and saving of a task item. Copy and paste in ThisOutlookSession
Private Sub NewTask_Open(Cancel As Boolean)
MsgBox "We want to create a new task."
End Sub
Private Sub NewTask_Write(Cancel As Boolean)
MsgBox "New task is saved. Put your code to e-mail something here."
End Sub

You need to save and restart outlook to let the trapping begin ...

Hope you'll like it.

Charlize

bnquinn
02-27-2009, 11:35 AM
Charlize

Thanks for the head-start.
I am making progress with this - linking my tasks to "Remember the Milk" to generate emails to nag me to do things.

Thanks again.

Ben.

Charlize
02-27-2009, 12:13 PM
Charlize

Thanks for the head-start.
I am making progress with this - linking my tasks to "Remember the Milk" to generate emails to nag me to do things.

Thanks again.

Ben.Your welcome, it was an interesting question and could be of some use for myself.

I was thinking a little further.

- What if the first e-mail was sent. You open the task and save it again. Do you want an email to be sent again or not ? If not, i used the subject of the task and added '- Email' to it. When opening again and probably saving I used the split function to check on this. If found, no email sent (just an idea).

If someone else has an idea (some nice coding is always appreciated) how to use the categories, I'm willing to absorb.

- When a task is marked completed, the task is saved again. I added a check to see if complete = true. If true, no mail has to be sent.

Charlize