+ Reply to Thread
Results 1 to 3 of 3

Can't send email automatically outlook 2007

Hybrid View

  1. #1
    Registered User
    Join Date
    10-18-2012
    Location
    Portugal
    MS-Off Ver
    Excel 2003
    Posts
    30

    Can't send email automatically outlook 2007

    I want o send an email from excel but I have to open the outlook otherwise the mail is not sent. Why the command oEmail.Send doesn't work. Any idea?
    Here is my code
    
    Dim oApp As Outlook.Application
    Dim oEmail As MailItem
    Dim colAttach As Outlook.Attachments
    Dim oAttach As Outlook.Attachment
        Set oApp = CreateObject("Outlook.Application")
        Set oEmail = oApp.CreateItem(olMailItem)
        oEmail.HTMLBody = "ola" & "<img src=""c:\senhora.jpg"" > " & vbNewLine
        oEmail.Save
        oEmail.Display
        oEmail.To = "myemail"
        oEmail.Subject = "Teste ao envio de email"
        oEmail.Send
        Set oEmail = Nothing
        Set colAttach = Nothing
        Set oAttach = Nothing
        Set oApp = Nothing

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Can't send email automatically outlook 2007

    Hello lopezio,

    I don't have Outlook 2007 but Outlook 2010 won't send the email unless the inspector for the inbox is active. Here is the code I use for Outlook 2010...
        Dim HTML As String 
        Dim olApp As Object
    
            Set olApp = CreateObject("Outlook.Application")
                olApp.Session.GetDefaultFolder 6
                With olApp.CreateItem(0)
                    .To = "[email protected]"
                    .Subject = "Weekly Schedule"
                    .HTMLBody = HTML
                    .Send
                End With
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    10-18-2012
    Location
    Portugal
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Can't send email automatically outlook 2007

    Hi Ross
    got error in outlook 2007, in instruction send
    Here is the error
    Application-defined or object-defined error
    This code works in outlook 2007
    Shell "outlook.exe", vbMinimizedFocus
    Dim oApp As Outlook.Application
    Dim oEmail As MailItem
    Dim colAttach As Outlook.Attachments
    Dim oAttach As Outlook.Attachment
        Set oApp = CreateObject("Outlook.Application")
        Set oEmail = oApp.CreateItem(olMailItem)
        oEmail.HTMLBody = "ola" & "<img src=""c:\senhora.jpg"" > " & vbNewLine
        oEmail.Save
        oEmail.Display
        oEmail.To = "myemail"
        oEmail.Subject = "Teste ao envio de email"
        oEmail.Send
        
    'MsgBox "terminei"
    Set oEmail = Nothing
        Set colAttach = Nothing
        Set oAttach = Nothing
        Set oApp = Nothing
    Shell "taskkill /F /IM outlook.exe", vbHide
    But I don't like it because I have to open outlook and kill the process.
    Any ideas?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 06-05-2013, 04:31 AM
  2. Replies: 5
    Last Post: 02-22-2013, 02:00 AM
  3. [SOLVED] VBA code - automatically open outlook to send email
    By LindaABH in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-06-2012, 01:44 AM
  4. Excel to automatically send an email from Outlook when a condition is met
    By Spyke in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-14-2011, 04:40 AM
  5. Getting error while trying to send email thru MS outlook 2007
    By sreerag446 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-03-2008, 05:25 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1