Advertisement
Joel-Tang

Forward to Toodledo Outlook Macros

Jul 30th, 2012
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.71 KB | None | 0 0
  1. Sub NextAction()
  2. Dim objMail As Outlook.MailItem
  3. Set objItem = GetCurrentItem()
  4. Set objMail = objItem.Forward
  5. objMail.To = "yourtoodledoemail@toodledo.com"
  6. ' see https://www.toodledo.com/info/help_email.php for proper syntax  for the following'
  7. objMail.Subject = objMail.Subject & " ! @context $status +goals *project"
  8. objMail.Display
  9. objMail.Categories = "Next Action"
  10. objMail.Send
  11. Set objItem = Nothing
  12. Set objMail = Nothing
  13. Call MoveToFolder
  14. End Sub
  15.  
  16. Function GetCurrentItem() As Object
  17. Dim objApp As Outlook.Application
  18. Set objApp = Application
  19. On Error Resume Next
  20. Select Case TypeName(objApp.ActiveWindow)
  21. Case "Explorer"
  22. Set GetCurrentItem = _
  23. objApp.ActiveExplorer.Selection.Item(1)
  24. Case "Inspector"
  25. Set GetCurrentItem = _
  26. objApp.ActiveInspector.CurrentItem
  27. Case Else
  28. End Select
  29. End Function
  30.  
  31. 'Outlook VB Macro to move selected mail item(s) to a target folder
  32. Sub MoveToFolder()
  33. On Error Resume Next
  34.  
  35. Dim ns As Outlook.NameSpace
  36. Dim moveToFolder As Outlook.MAPIFolder
  37. Dim objItem As Outlook.MailItem
  38.  
  39. Set ns = Application.GetNamespace("MAPI")
  40.  
  41. 'Define path to the target folder
  42. Set moveToFolder = ns.Folders("yourEmail@Email.com").Folders("Active").Folders("Project")
  43.  
  44. If Application.ActiveExplorer.Selection.Count = 0 Then
  45.    MsgBox ("No item selected")
  46.    Exit Sub
  47. End If
  48.  
  49. If moveToFolder Is Nothing Then
  50.    MsgBox "Target folder not found!", vbOKOnly + vbExclamation, "Move Macro Error"
  51. End If
  52.  
  53. For Each objItem In Application.ActiveExplorer.Selection
  54.    If moveToFolder.DefaultItemType = olMailItem Then
  55.       If objItem.Class = olMail Then
  56.          objItem.Move moveToFolder
  57.       End If
  58.   End If
  59. Next
  60.  
  61. Set objItem = Nothing
  62. Set moveToFolder = Nothing
  63. Set ns = Nothing
  64.  
  65. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement