Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. ### Create a form
  2.  
  3. Below method uses 2 textBoxes from form
  4.  
  5. ```vba
  6. Private Sub sendButton_Click()
  7. Dim text As String
  8. Dim i As Integer
  9. Dim entry As String
  10. Dim entries() As String
  11. Dim objOutlook As Outlook.Application
  12. Dim objOutlookMsg As Outlook.MailItem
  13. Dim objOutlookRecip As Outlook.Recipient
  14.  
  15. text = "[prevday]" & vbNewLine
  16. entries = Split(UserForm1.prevText.Value, vbNewLine)
  17. For i = LBound(entries) To UBound(entries)
  18. text = text & "XXX: " & entries(i) & vbNewLine
  19. Next
  20.  
  21. text = text & vbNewLine & "[today]" & vbNewLine
  22. entries = Split(UserForm1.todayText.Value, vbNewLine)
  23. For i = LBound(entries) To UBound(entries)
  24. text = text & "YYY: " & entries(i) & vbNewLine
  25. Next
  26.  
  27. ' Create the Outlook session.
  28. Set objOutlook = CreateObject("Outlook.Application")
  29.  
  30. ' Create the message.
  31. Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
  32.  
  33. Set objOutlookRecip = objOutlookMsg.Recipients.Add("some@mail.example.org")
  34. objOutlookRecip.Type = olTo
  35.  
  36. objOutlookMsg.Subject = "[SubjectTag] " & Format(Date, "yyyymmdd")
  37. objOutlookMsg.Body = text
  38. objOutlookMsg.BodyFormat = olFormatPlain
  39.  
  40. objOutlookMsg.Send
  41.  
  42. ` MsgBox ("Send")
  43. ` clean
  44. UserForm1.todayText.Value = ""
  45. UserForm1.prevText.Value = ""
  46. UserForm1.Hide
  47.  
  48. End Sub
  49.  
  50. ```
  51.  
  52. ### create public method in module
  53. ```vba
  54. Public Sub ShowMyForm()
  55. UserForm1.Show
  56. End Sub
  57. ```
  58.  
  59. ### add Button to ToolBar
  60.  
  61. ShowMyForm should be in Marcors
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement