Send Email via VBA from Excel 2010

dariuzthepole

Board Regular
Joined
Jul 23, 2008
Messages
111
Hi folks,

This problem is driving me crazy. Please help!

I have a macro in Excel and when it finishes, I want to send myself and a colleague a simple text email advising the macro has finished running. The issue I've got is he is using WinXP and Office 2007, whereas I am using Win7 and Office 2010. He can get the following code to run fine and the email works:

Code:
Sub SendEmail(EmailAddress As String, Subject As String, Message As String)
     
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    sTo = EmailAddress
    sCC = ""
    sBCC = ""
    sSubject = Subject
    strbody = Message
    With OutMail
        .To = sTo
        .CC = sCC
        .BCC = sBCC
        .Subject = sSubject
        .Body = strbody
        .Send
    End With
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

When I try to run the macro from Excel 2010, the email does not get sent. I have added the MS Excel/Office 14.0 Object Library and MS Scripting Runtime references so that they are ticked but I cannot figure out the alterations I need to make the code operational.

N.B. The three variables (EmailAddress, Subject and Message) are defined in a Workbook_Open macro that kicks a series of macros off.

Any help would be greatly appreciated!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi,
Not sure why this question did not get any response. Please make sure that outlook is running when you run the macro to send email from excel. Else it might stay in the Outbox till you open the MS Outlook.
If the problem still persists, please upload a sample Excel document, so that someone could try to resolve the actual bug.

Reference Article on how to send email from Excel to multiple recipients.

Thanks and Hope this helps.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top