VBA, send email from Word

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • perhapscwk
    New Member
    • Sep 2007
    • 123

    #1

    VBA, send email from Word

    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.

    Code:
    Sub SendDocumentInMail()
    
    Dim bStarted As Boolean
    Dim oOutlookApp As New Outlook.Application
    Dim oItem As Outlook.MailItem
    
    
    On Error Resume Next
    
    'Get Outlook if it's running
    Set oOutlookApp = GetObject(, "Outlook.Application")
    If Err <> 0 Then
        'Outlook wasn't running, start it from code
        Set oOutlookApp = CreateObject("Outlook.Application")
        bStarted = True
    End If
    
    'Create a new mailitem
    Set oItem = oOutlookApp.CreateItem(olMailItem)
    
    With oItem
        'Set the recipient for the new email
    
       .To = "aaa@hotmail.com"
        'Set the recipient for a copy
        .CC = "aaa@hotmail.com"
        'Set the subject
        .Subject = "New subject"
        'The content of the document is used as the body for the email
        .body = ActiveDocument.Content
        .Send
    End With
    
    If bStarted Then
        'If we started Outlook from code, then close it
        oOutlookApp.Quit
    End If
    
    'Clean up
    Set oItem = Nothing
    Set oOutlookApp = Nothing
    
    End Sub
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Do you access botht the mail accounts from the same windows login ?

    Comment

    • perhapscwk
      New Member
      • Sep 2007
      • 123

      #3
      yes....with same login

      Comment

      Working...