Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to send email if button is clicked in Excel?

Supposing you need to send email through Outlook by clicking a button in Excel worksheet, how can you do? This article will introduce a VBA method to achieve it in details.

Send email if button is clicked with VBA code


Easily send email through Outlook based on created mailing list:

The Send Emails utility of Kutools for Excel helps users sending email through Outlook based on created mailing list in Excel. See screen shot:

Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days. Download and free trial Now!

Excel Productivity Tools

Office Tab: Bring powerful tabs to Office (include Excel), just like Chrome, Safari, Firefox and Internet Explorer. Save you half the time, and reduce thousands of mouse clicks for you. 30-day Unlimited Free Trial

Kutools for Excel: Save 70% of your time and solve 80% Excel problems for you. 300+ advanced features designed for 1500+ work scenario, make Excel much easy and increase productivity immediately. 60-day Unlimited Free Trial


Send email if button is clicked with VBA code


Please do as follows to send an email through Outlook if a Command Button is clicked in Excel workbook.

1. Insert a Command Button in your worksheet by clicking Developer > Insert > Command Button (ActiveX Control). See screenshot:

2. Right-click the inserted Command Button, then click View Code from the right-clicking menu as below screenshot show.

3. In the opening Microsoft Visual Basic for Applications window, please replace the original code in the Code window with the following VBA script.

VBA code: Send email if button is clicked in Excel

Private Sub CommandButton1_Click()
'Updated by Extendoffice 2017/9/14
    Dim xOutApp As Object
    Dim xOutMail As Object
    Dim xMailBody As String
    On Error Resume Next
    Set xOutApp = CreateObject("Outlook.Application")
    Set xOutMail = xOutApp.CreateItem(0)
    xMailBody = "Body content" & vbNewLine & vbNewLine & _
              "This is line 1" & vbNewLine & _
              "This is line 2"
                  On Error Resume Next
    With xOutMail
        .To = "Email Address"
        .CC = ""
        .BCC = ""
        .Subject = "Test email send by button clicking"
        .Body = xMailBody
        .Display   'or use .Send
    End With
    On Error GoTo 0
    Set xOutMail = Nothing
    Set xOutApp = Nothing
End Sub

Notes:

1). Please change the email body as you need in the xMailBody line in the code.

2). Replace the Email Address with the recipient email address in line .To = "Email Address".

3). Specify the Cc and Bcc recipients as you need in .CC = “” and .Bcc = “” sections.

4). Change the email subject in line .Subject = "Test email send by button clicking".

4. Press the Alt + Q keys simultaneously to close the Microsoft Visual Basic for Applications window.

5. Turn off the Design Mode by clicking Developer > Design Mode. See screenshot:

From now on, every time you click on the Command Button, an email will be created automatically with specified recipients, subject and body. Please send the email by clicking the Send button.

Note: The VBA code is only working when you use Outlook as your email program.


Related articles:


Excel Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 70%, and Help You To Stand Out From Crowd!

Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 80% Excel problems.

  • Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
  • Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  • Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
  • Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
  • No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
  • Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
  • 60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  • Change the way you work now, and give you a better life immediately!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    kaitlyn k. · 3 days ago
    Do you have to be an excel user when pushing the button to send an email? or just the person receiving the email has to be an outlook user?
  • To post as a guest, your comment is unpublished.
    John · 18 days ago
    Hi,

    How can I get the mail to automatically add my signature from outlook?
  • To post as a guest, your comment is unpublished.
    Rasike · 3 months ago
    Hi There,
    Can anyone could help me on the following requirement?
    I have an excel sheet having two drop down lists.

    1 drop down list- list of departments

    2 drop down list- category

    What i want is when I select a department and category from the lists;(for example if I select "sales" in department and "monthly report" in category)

    I need to email the PDF version of that work sheet to the sales team with the email subject is monthly report.

    If i select "production" from the department list, the email should go to a group of people in the production.

    I appreciate if you can help me on this

    Rasike
  • To post as a guest, your comment is unpublished.
    Abi · 3 months ago
    Can I reference the value in a cell in the subject with string? Some variation of the below?

    .Subject = "New Event:" & Target.Address = "$B$38"
    • To post as a guest, your comment is unpublished.
      crystal · 3 months ago
      Hi Abi,
      Please change the code to .Subject = "New Event:" & [B38].
      Thank you for your comment.
  • To post as a guest, your comment is unpublished.
    Laurie · 4 months ago
    Is it possible to, instead of sending the attachment in the email, to send a hyperlink to the file (located on SharePoint)?
    • To post as a guest, your comment is unpublished.
      crystal · 3 months ago
      Hi Laurie,
      Can't help you with that. Thank you for your comment.