Results 1 to 4 of 4

Thread: Outlook task event

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    6

    Outlook task event

    I am using outlook 2003 you can assign a task and send it to another person and it stays in the other person email until he accepts it, i want to automatically accept the task for the user, i can't find an event which gets triggered
    can anyone there help me please
    thanks heaps

  2. #2

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    6

    Re: Outlook task event

    Hi, i found this

    This Microsoft Visual Basic/Visual Basic for Applications (VBA) example accepts a TaskRequestItem, sending the response without displaying the inspector.

    Sub AcceptTask()
    Dim myOlApp As New Outlook.Application
    Dim myNameSpace As Outlook.NameSpace
    Dim myTasks As Outlook.MAPIFolder
    Dim myNewTaskItem As Outlook.TaskItem
    Dim mytaskreqItem As Outlook.TaskRequestItem
    Dim myItem As Outlook.TaskItem
    Set myNameSpace = myOlApp.GetNamespace("MAPI")
    Set myTasks = myNameSpace.GetDefaultFolder(olFolderInbox)
    Set mytaskreqItem = myTasks.Items.Find("[Subject] = ""Meeting w/ Nate Sun""")
    If Not TypeName(mytaskreqItem) = "Nothing" Then
    Set myNewTaskItem = mytaskreqItem.GetAssociatedTask(True)
    Set myItem = myNewTaskItem.Respond(olTaskAccept, True, True)
    myItem.Send
    End If
    End Sub

    however i think this one assumes that we know the subject name of the email that has the taskrequestitem is there's a way to go around that?
    or even another totally different way @@?

  3. #3
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: Outlook task event

    Can't you just catch them in the inbox when new mail arrives? Here's a bit of sample code, you'll have to add something to screen the ones that you want to autorespond to, but this should give you a start. Drop this "ThisOutlookSession".
    VB Code:
    1. Private Sub Application_NewMail()
    2.  
    3.     Dim oInBox As MAPIFolder, oItem As Object, oResponse As TaskItem
    4.    
    5.     Set oInBox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
    6.    
    7.     For Each oItem In oInBox.Items
    8.         If TypeName(oItem) = "TaskItem" Then
    9.             Set oResponse = oItem.Respond(olTaskAccept, True, False)
    10.             oResponse.Send
    11.         End If
    12.     Next oItem
    13.  
    14.     Set oResponse = Nothing
    15.     Set oInBox = Nothing
    16.  
    17. End Sub

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Outlook task event

    Since your using Outlook 2003 you can use the Application_NewMailEx event as it passes in a parameter of the newmailitem. Then instead of looping through the items you can just use the referenced Item and test for its type and/or its subject like you were doing.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width