Advertisement
goezler

Send multiple files in Outlook with Send to menu

Nov 5th, 2021
763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 1. Create a new *.vbs file: "Sent to Outlook.vbs" and insert below script:
  2. 2. Then make a shortcut in c:\users\[username]\AppData\Roaming\Microsoft\Windows\SendTo
  3. ----------------------------------------------------------------
  4.  
  5. Option Explicit
  6. Dim objArgs, OutApp, oNameSpace, oInbox, oEmailItem, olMailItem
  7. Dim a, oAttachments, subjectStr, olFormatHTML
  8. olMailItem = 0
  9. olFormatHTML = 2
  10. Set objArgs = WScript.Arguments 'gets paths of selected files
  11. Set OutApp = CreateObject("Outlook.Application") 'opens Outlook
  12. Set oEmailItem = OutApp.CreateItem(olMailItem) ' opens new email
  13. For a = 0 to objArgs.Count - 1
  14. Set oAttachments = oEmailItem.Attachments.Add(objArgs(a))
  15. subjectStr = subjectStr & Right(objArgs(a),Len(objArgs(a))-(InStrRev(objArgs(a),"\"))) & ", " 'recreates the default Subject e.g. Emailing: file1.doc, file2.xls
  16. Next
  17. If subjectStr = "" then subjectStr = "No Subject "
  18. oEmailItem.Subject = "Emailing: " & Left(subjectStr, (Len(subjectStr)-2))
  19. oEmailItem.BodyFormat = olFormatHTML
  20. oEmailItem.DisplayOption Explicit
  21. Dim objArgs, OutApp, oNameSpace, oInbox, oEmailItem, olMailItem
  22. Dim a, oAttachments, subjectStr, olFormatHTML
  23. olMailItem = 0
  24. olFormatHTML = 2
  25. Set objArgs = WScript.Arguments 'gets paths of selected files
  26. Set OutApp = CreateObject("Outlook.Application") 'opens Outlook
  27. Set oEmailItem = OutApp.CreateItem(olMailItem) ' opens new email
  28. For a = 0 to objArgs.Count - 1
  29. Set oAttachments = oEmailItem.Attachments.Add(objArgs(a))
  30. subjectStr = subjectStr & Right(objArgs(a),Len(objArgs(a))-(InStrRev(objArgs(a),"\"))) & ", " 'recreates the default Subject e.g. Emailing: file1.doc, file2.xls
  31. Next
  32. If subjectStr = "" then subjectStr = "No Subject "
  33. oEmailItem.Subject = "Emailing: " & Left(subjectStr, (Len(subjectStr)-2))
  34. oEmailItem.BodyFormat = olFormatHTML
  35. oEmailItem.Display
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement