Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. Sub SendDocAsMail()
  2.  
  3. Dim oOutlookApp As Outlook.Application
  4. Dim oItem As Outlook.MailItem
  5.  
  6. On Error Resume Next
  7.  
  8. 'Start Outlook if it isn't running
  9. Set oOutlookApp = GetObject(, "Outlook.Application")
  10. If Err <> 0 Then
  11. Set oOutlookApp = CreateObject("Outlook.Application")
  12. End If
  13.  
  14. 'Create a new message
  15. Set oItem = oOutlookApp.CreateItem(olMailItem)
  16. oItem.Subject = "Testing"
  17. oItem.To = "nsmith@metroinsurance.com"
  18.  
  19. 'Copy the open document
  20. Selection.WholeStory
  21. Selection.Copy
  22. Selection.End = True
  23.  
  24. Dim finderTo
  25. 'finderTo = Selection.Find.Execute FindText:="library"
  26. 'finderTo = wdEditor.Characters
  27.  
  28. 'Set the WordEditor
  29. Dim objInsp As Outlook.Inspector
  30. Dim wdEditor As Word.Document
  31. Set objInsp = oItem.GetInspector
  32. Set wdEditor = objInsp.WordEditor
  33.  
  34. Dim whateverThis As String
  35. extractorString = ActiveDocument.Content
  36. extractorString = extractorString.Find.ClearFormatting
  37.  
  38. 'Dim firstPos As Integer
  39. 'Dim secondPost As Integer
  40. 'Dim strExtracted As String
  41. 'firstPos = 2
  42. 'firstPos = extractorString.InStr("doc")
  43. 'secondPos = extractorString.InStr("]]]")
  44. Dim xEmail As String
  45. Dim xSubject As String
  46. Dim txt As String
  47.  
  48. 'Extract Email Address
  49.  
  50. 'txt = extractorString
  51. 'pFirst = InStr(txt, "@@((")
  52. 'pSecond = InStr(txt, "**))")
  53. 'strExtracted = Mid(txt, pFirst, pSecond)
  54. 'xEmail = strExtracted
  55. 'xEmail = Replace(xEmail, "@@((", "")
  56. 'xEmail = Replace(xEmail, "**))", "")
  57. 'whatever = Len(xEmail)
  58.  
  59.  
  60. 'Extract Subject Line
  61. txt = extractorString
  62. pFirst = InStr(txt, "{{{")
  63. pSecond = InStr(txt, "}}}")
  64. strExtracted = Mid(txt, pFirst, pSecond)
  65. xSubject = strExtracted
  66. xSubject = Replace(xSubject, "{{{", "")
  67. xSubject = Replace(xSubject, "}}}", "")
  68. oItem.Subject = xSubject
  69.  
  70. 'Extract test Line
  71. txt = extractorString
  72. pFirst = InStr(txt, "[[[")
  73. pSecond = InStr(txt, "]]]")
  74. strExtracted = Mid(txt, pFirst, pSecond)
  75. xTest = strExtracted
  76. xTest = Replace(xTest, "[[[", "")
  77. xTest = Replace(xTest, "]]]", "")
  78. oItem.To = xTest
  79.  
  80. x = 2
  81. 'Write the intro if specified
  82. Dim i As Integer
  83. i = 1
  84.  
  85.  
  86. 'Comment the next line to leave your default signature below the document
  87. 'wdEditor.Content.Delete
  88.  
  89.  
  90. 'Place the current document under the intro and signature
  91. wdEditor.Characters(i).PasteAndFormat (wdFormatOriginalFormatting)
  92.  
  93. 'Display the message
  94. oItem.Display
  95.  
  96. 'Clean up
  97. Set oItem = Nothing
  98. Set oOutlookApp = Nothing
  99. Set objInsp = Nothing
  100. Set wdEditor = Nothing
  101.  
  102. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement