Search code examples
excelexcel-2010excel-2007vba

Sending outlook emails from Excel


I have the below VBA that sends an email fine:

    With Sendrng

        ' Select the worksheet with the range you want to send
        .Parent.Select

        'Remember the ActiveCell on that worksheet
        Set rng = ActiveCell

        'Select the range you want to mail
        .Select

        ' Create the mail and send it
        ActiveWorkbook.EnvelopeVisible = True
        With .Parent.MailEnvelope

            ' Set the optional introduction field thats adds
            ' some header text to the email body.
            .Introduction = ""

            With .Item
                .To = "123@321.com"
                .CC = ""
                .BCC = ""
                .Subject = "A new deli pre-order has been received."
                .Send
            End With

The part where I am now struggling is to set who the email has come from

I thought adding the below would work:

 .From = "111@222.com"

What happens when adding the above: No email is received at all

What am I missing?


Solution

  • You can try .SendUsingAccount to select the account which you are going to send the e-mail.

    With .Item
        .SendUsingAccount = olAccount 'or some other account.
        .To = "123@321.com"
        .CC = ""
        .BCC = ""
        .Subject = "A new deli pre-order has been received."
        .Send
    End With