VBA to generate email

BearGilchrist

New Member
Joined
Apr 23, 2018
Messages
10
Hi guys,

I need a simple VBA code that will open a new email in outlook and with the TO and CC recipients predefined and the subject line prefilled.

Pretty much a newbie to VBA so any help resources for beginners you find useful would be helpful too.

Thanks in advance.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
try this out

Code:
Private Sub SendEmail()
 Dim OutlookApp As Object
    Dim MItem As Object
    Dim email_ As String
    Dim subject_ As String
    Dim body_ As String
     
    Set OutlookApp = CreateObject("Outlook.Application")
     
    email_ = "Your TO here"
    subject_ = "Your SUBJECT here"
    body_ = "Whatever you want as the body"
     
     'create Mail Item and send it
    Set MItem = OutlookApp.CreateItem(0)
     
    Application.DisplayAlerts = False
    With MItem
        .To = email_
        .Subject = subject_
        .Body = body_
        .Send
    End With
    Application.DisplayAlerts = True

End Sub
 
Upvote 0
Hi,

Thanks for that, so i had something similar to this however i don't want it to automatically send. I removed the .send to stop this but then the item doesn't even open, thoughts?
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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