Consulting

Results 1 to 4 of 4

Thread: Auto-email when task added

  1. #1
    VBAX Newbie
    Joined
    Feb 2009
    Posts
    3
    Location

    Auto-email when task added

    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.

  2. #2
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Place every coding in the ThisOutlookSession. The code that follows here must be placed all the way up in your module.
    [vba]'*** 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[/vba]
    The next piece of coding needs to be placed in the Application_Quit section.
    [vba]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[/vba]
    This piece in the Application_Startup section
    [vba]Private Sub Application_Startup()
    'Don't copy the private sub application_startup. Only the code ...
    Set objinspectors = Application.Inspectors
    End Sub[/vba]
    This is a new piece of coding to trap 'objinspectors' ie. copy and paste in ThisOutlookSession.
    [vba]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[/vba]
    And now the two pieces that deal with the creating and saving of a task item. Copy and paste in ThisOutlookSession
    [vba]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[/vba]

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

    Hope you'll like it.

    Charlize

  3. #3
    VBAX Newbie
    Joined
    Feb 2009
    Posts
    3
    Location

    Thanks

    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.

  4. #4
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Quote Originally Posted by bnquinn
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •