Solved

How can I auto accept task in Outlook 2007, with VBScript?

Posted on 2011-03-03
2
1,315 Views
Last Modified: 2012-05-11
I have Outlook 2007, over windows XP SP3, and I developed the following code to create tasks and assign them to the people who helps me at work:

  Sub CreateTaskItem(strSubject,strDueDate,strBody,StrDelegate,strCategory,intID)
    Const olTaskItem = 3
    'Creates an Automation object of the specified class
    Set OutlookApp = CreateObject("Outlook.Application")
    'Creates and returns a new Microsoft Outlook item (item: An item is the basic element that holds information in Outlook)
    Set oItems = OutlookApp.CreateItem(olTaskItem)
    'Assigns a task and returns a TaskItem object that represents it.
    'This method allows a task to be assigned (delegated) to another user.
    'You must create a task before you can assign it, and you must assign a task before you can send it.
    'An assigned task is sent as a TaskRequestItem object.
    oItems.Assign
    Set myDelegate = oItems.Recipients.Add(StrDelegate)
    myDelegate.Resolve
    If myDelegate.Resolved Then
      'String indicating the subject for the Outlook item
      oItems.Subject = strSubject
      'Date indicating the due date for the task
      oItems.DueDate = strDueDate
      'String representing the clear-text body of the Outlook item
      oItems.Body = strBody
      'String representing the categories assigned to the Outlook item
      oItems.Categories = strCategory
      'String representing the names of the companies associated with the Outlook item. In this code, Categories info is saved.
      oItems.Companies = strCategory
      'String representing the billing information associated with the Outlook item. In this code is used to assing and unique ID to this Task
      oItems.BillingInformation = CStr(intID)
      'String representing the mileage for an item. Read/write.
      oItems.Mileage = "CRCD Guadalupe"
      'Occurs when the user selects the Send action for an item, or when the Send method is called for the item, which is an instance of the parent object
      oItems.Send
    End If
    Set oItems = Nothing
    Set OutlookApp = Nothing
  End Sub

Open in new window


This code works all right, Can anybody help me to develop the VBScript code to automatically accept the task I send to my coworkers? I want to save time and work to my coworkers, accepting every task I assign them.

Thanks,
migcsha
0
Comment
Question by:shamigc3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
speshalyst earned 500 total points
ID: 35036090
0
 

Author Comment

by:shamigc3
ID: 35043786
speshalyst:

Hi, I improved code adding "Restrict" method, and used on Outlok 2007 with success:
  Sub AcceptTasks()
  'Code based from http://msdn.microsoft.com/en-us/library/bb207065
    Const olFolderInbox = 6, olTaskAccept = 2

    Set OutlookApp = CreateObject("Outlook.Application")
    'NameSpace object of the specified type
    Set myNameSpace = OutlookApp.GetNameSpace("MAPI")
    'GetDefaultFolder:Folder object that represents the default folder of the requested type for the current profile
    Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
    'Select all TaskRequestItems items inside folder
    sFilter = "[MessageClass] = 'IPM.TaskRequest'"
    Set myTaskRequestItems = myFolder.Items.Restrict(sFilter)
    For Each TaskRequestItem In myTaskRequestItems
      Set AssociatedTaskRequestItem = TaskRequestItem.GetAssociatedTask(True)
      Set myItem = AssociatedTaskRequestItem.Respond(olTaskAccept, True, True)
      myItem.Send
    Next
    Set TaskRequestItem = Nothing
    Set AssociatedTaskRequestItem = Nothing
    Set myItem = Nothing
    Set myTaskRequestItems = Nothing
    Set myFolder = Nothing
    Set myNameSpace = Nothing
    Set OutlookApp = Nothing
  End Sub

Open in new window


Thanks,
migcsha
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Changing a few Outlook Options can help keep you organized!
This article describes how to import Lotus Notes Contacts into Outlook 2016, 2013, 2010 and 2007 etc. with a few manual steps. You can easily export and migrate Lotus Notes contacts into Microsoft Outlook without having to use any third party tools.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question