Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
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.
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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