Solved

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

Posted on 2011-03-03
2
1,299 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
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now