Guest User

Untitled

a guest
Oct 18th, 2017
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. Sub Which_Account_Number()
  2. 'Don't forget to set a reference to Outlook in the VBA editor
  3. Dim OutApp As Outlook.Application
  4. Dim I As Long
  5.  
  6. Set OutApp = CreateObject("Outlook.Application")
  7.  
  8. For I = 1 To OutApp.Session.Accounts.Count
  9. MsgBox OutApp.Session.Accounts.Item(I) & " : This is account number " & I
  10. Next I
  11. End Sub
  12.  
  13. Sub Mail_small_Text_Change_Account()
  14. 'Only working in Office 2007-2016
  15. 'Don't forget to set a reference to Outlook in the VBA editor
  16. Dim OutApp As Outlook.Application
  17. Dim OutMail As Outlook.MailItem
  18. Dim strbody As String
  19.  
  20. Set OutApp = CreateObject("Outlook.Application")
  21. Set OutMail = OutApp.CreateItem(olMailItem)
  22.  
  23. strbody = "Hi there" & vbNewLine & vbNewLine & _
  24. "This is line 1" & vbNewLine & _
  25. "This is line 2" & vbNewLine & _
  26. "This is line 3" & vbNewLine & _
  27. "This is line 4"
  28.  
  29. On Error Resume Next
  30. With OutMail
  31. .To = "ron@debruin.nl"
  32. .CC = ""
  33. .BCC = ""
  34. .Subject = "This is the Subject line"
  35. .Body = strbody
  36.  
  37. 'SendUsingAccount is new in Office 2007
  38. 'Change Item(1)to the account number that you want to use
  39. .SendUsingAccount = OutApp.Session.Accounts.Item(1)
  40.  
  41. .Send 'or use .Display
  42. End With
  43. On Error GoTo 0
  44.  
  45. Set OutMail = Nothing
  46. Set OutApp = Nothing
  47. End Sub
Add Comment
Please, Sign In to add comment