By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,378 Members | 3,020 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,378 IT Pros & Developers. It's quick & easy.

VBA, send email from Word

100+
P: 123
I use below to send email, however, i have 2 mailbox in outllok..it always
use the first one to send. How i can set it to set from the other email account?

thanks.

Expand|Select|Wrap|Line Numbers
  1. Sub SendDocumentInMail()
  2.  
  3. Dim bStarted As Boolean
  4. Dim oOutlookApp As New Outlook.Application
  5. Dim oItem As Outlook.MailItem
  6.  
  7.  
  8. On Error Resume Next
  9.  
  10. 'Get Outlook if it's running
  11. Set oOutlookApp = GetObject(, "Outlook.Application")
  12. If Err <> 0 Then
  13.     'Outlook wasn't running, start it from code
  14.     Set oOutlookApp = CreateObject("Outlook.Application")
  15.     bStarted = True
  16. End If
  17.  
  18. 'Create a new mailitem
  19. Set oItem = oOutlookApp.CreateItem(olMailItem)
  20.  
  21. With oItem
  22.     'Set the recipient for the new email
  23.  
  24.    .To = "aaa@hotmail.com"
  25.     'Set the recipient for a copy
  26.     .CC = "aaa@hotmail.com"
  27.     'Set the subject
  28.     .Subject = "New subject"
  29.     'The content of the document is used as the body for the email
  30.     .body = ActiveDocument.Content
  31.     .Send
  32. End With
  33.  
  34. If bStarted Then
  35.     'If we started Outlook from code, then close it
  36.     oOutlookApp.Quit
  37. End If
  38.  
  39. 'Clean up
  40. Set oItem = Nothing
  41. Set oOutlookApp = Nothing
  42.  
  43. End Sub
  44.  
May 29 '08 #1
Share this Question
Share on Google+
2 Replies


debasisdas
Expert 5K+
P: 8,127
Do you access botht the mail accounts from the same windows login ?
May 29 '08 #2

100+
P: 123
yes....with same login
May 29 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.