Solved

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

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Learn more about how the humble email signature can be used as more than just an electronic business card. When used correctly, a signature can easily be tailored for different purposes by different departments within an organization.
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
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 …
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…

762 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

22 Experts available now in Live!

Get 1:1 Help Now