I’ve created a couple of custom VBA functions for Outlook 2007 from some snippets at www.outlookcode.com and thought that someone else may find them useful. The first allows you to create a task from an email and modify the Update List recipients (something that you cannot do manually). This also works in Outlook 2003. The second is a timestamp that allows you to inject a timestamp into a task body without modifying the format of the body (using the Word object library).


Create a Task from an Email with the Ability to add Update List Recipients


Instructions: Copy the code below and paste it into the VBA editor in Outlook (access the editor by pressing ALT+F11 in Outlook). Then create a button on the Quick Access Toolbar for mail messages that accesses the MakeTaskFromEmail() function.

Sub MakeTaskFromEmail()
   Dim strID As String
   Dim olNS As Outlook.NameSpace
   Dim olMail As Outlook.MailItem
   Dim objTask As Outlook.TaskItem
   Set objMail = Outlook.Application.ActiveInspector.CurrentItem

   strID = objMail.EntryID
   Set olNS = Application.GetNamespace(”MAPI”)
   Set olMail = olNS.GetItemFromID(strID)
   Set objFolder = olNS.PickFolder
   Set objTask = objFolder.Items.Add(olTaskItem)
   objRecipients = InputBox(”Please enter any additional users to Update separated by semicolons:”, “Update List Users”)
    With objTask
      .Subject = olMail.Subject
      .Body = olMail.Body
      .StatusUpdateRecipients = olMail.SenderEmailAddress & “; ” & objRecipients
      .StatusOnCompletionRecipients = olMail.SenderEmailAddress & “; ” & objRecipients
   End With

   Call TaskAttachments(olMail, objTask)

   objTask.Display

   Set objTask = Nothing
   Set olMail = Nothing
   Set olNS = Nothing
End Sub

Sub TaskAttachments(objSourceItem, objTargetItem)
   Set fso = CreateObject(”Scripting.FileSystemObject”)
   Set fldTemp = fso.GetSpecialFolder(2)
   strPath = fldTemp.Path & “\”
   For Each objAtt In objSourceItem.Attachments
      strFile = strPath & objAtt.FileName
      objAtt.SaveAsFile strFile
      objTargetItem.Attachments.Add strFile, , , objAtt.DisplayName
      fso.DeleteFile strFile
   Next

   Set fldTemp = Nothing
   Set fso = Nothing
End Sub


TimeStamp Using WordEditor in Outlook 2007


Instructions: Copy the code below and paste it into the VBA editor in Outlook (access the editor by pressing ALT+F11 in Outlook). Then create a button on the Quick Access Toolbar for tasks that accesses the TimeStamp() function. You will also have to enable the Word object library in Tools -> References in the VBA editor.

Sub TimeStamp()
   Dim strText As String
   Dim objItem As Object
   Dim objExpl As Outlook.Explorer
   Dim objInsp As Outlook.Inspector
   Dim objDoc As Word.Document
   On Error Resume Next

   Set objNameSpace = Application.GetNamespace(”MAPI”)
   MyName = objNameSpace.CurrentUser.Name
   strText = “>> ” & Date & ” ” & Time & ” ” & MyName & “:” & vbCrLf & vbCrLf & vbCrLf

   Set objExpl = Application.ActiveExplorer
   Set objItem = objExpl.Selection(1)
   If Not objItem Is Nothing Then
      Set objInsp = objItem.GetInspector
      If objInsp.EditorType = olEditorWord Then
         Set objDoc = objInsp.WordEditor
         objDoc.Characters(1).InsertBefore strText
      Else
         MsgBox “Cannot insert text in a formatted message unless Word is the editor”
      End If
   End If

   Set objInsp = Nothing
   Set objDoc = Nothing
   Set objExpl = Nothing
   Set objItem = Nothing
   Set objMsg = Nothing
End Sub