Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending mail using Outlook where the Send method fails

I use this code to send email from Excel:

Sub Mail_workbook_Outlook_1()
'Working in Excel 2000-2013
'This example send the last saved version of the Activeworkbook
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
    Dim OutApp As Object
    Dim OutMail As Object

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
    With OutMail
        .to = "[email protected]"
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .Body = "Hi there"
        .Attachments.Add ActiveWorkbook.FullName
        'You can add other files also like this
        '.Attachments.Add ("C:\test.txt")
        .Send ' <--------------------------------This is causing troubble
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

The problem is that .Send is not recognized as an object (or method).

Other commands are working (i.e. Display, Save).

I believe this error exists because of security systems at my work. I have even tried using CDO and it is not working ether.

like image 422
Ole Henrik Skogstrøm Avatar asked Oct 21 '22 04:10

Ole Henrik Skogstrøm


1 Answers

Change .Send to .Display and put SendKeys "^{ENTER}" before the With OutMail line.

like image 64
Tim Richards Avatar answered Oct 24 '22 03:10

Tim Richards