How to Email with Attachment

excelpunk

Board Regular
Joined
May 6, 2011
Messages
165
Hello Everyone,

I am stuck while working on Excel. I guess this is a very small issue but I would certainly appreciate if someone can help me:
I am trying to email a person with a attachment using Excel. The issue is the 'Email Client' will change from one PC to other. Is it possible to send a email with a attachment using VBA? (Without specifying the email client).

If not, then can someone help me assuming email client as 'Outlook' or 'Windows Email'.

Please note: I have subject and Body entered in few cells, so it would be great if the code can actually read those and would automatically send a email with the subject, body & attachment.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Code:
sub email()
 
Dim outapp As Object
Dim outmail As Object
dim sBody as string
 
sBody = range("b3").value
 

Set outapp = CreateObject("Outlook.Application")
Set outmail = outapp.createitem(0)
With outmail
        .To = ""
         .CC = ""
        .Subject = sBody        
        .body = ""
        .Attachments.Add ""
        .display
        SendKeys "%{s}", True 
End With
Application.Wait (Now + TimeValue("00:00:05"))
SendKeys "%{s}", True 
Set outapp = Nothing
Set outmail = Nothing

Works with outlook
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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