Solved

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

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

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

Suggested Solutions

Title # Comments Views Activity
problem with office 365 portal 7 42
Outlook combined inbox 8 61
INSERT value into first row in 75 workbooks 8 33
MS Exchange 2016 license 5 23
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

739 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