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 with copying and pasting a specified range into email body in Excel?

In many cases, a specified range of contents in Excel worksheet may be useful in your email communication. In this article, we will introduce a method of sending an email with specified range pasting into email body directly in Excel.

Send email with a specified range pasted into email body in Excel


Send email with a specified range pasted into email body in Excel


The following VBA code can help you to copy a range and paste it into an email body directly in Excel. Please do as follows.

1. In the worksheet contains the range you need to copy, press the Alt + F11 keys simultaneously to open the Microsoft Visual Basic for Applications window.

2. In the opening Microsoft Visual Basic for Applications window, please click Tools > References as below screenshot shown.

3. In the References – VBAProject dialog box, please find and check the Microsoft Outlook Object Library option, and then click the OK button.

4. Click Insert > Module, then copy and paste the below VBA code into the Module window.

VBA code: Send email with a specified range pasted into email body in Excel

Sub Send_Email()
    Dim xRg As Range
    Dim I, J As Long
    Dim xAddress As String
    Dim xEmailBody As String
    Dim xMailOut As Outlook.MailItem
    Dim xOutApp As Outlook.Application    
    On Error Resume Next
    xAddress = ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("Please select range you need to paste into email body", "KuTools For Excel", xAddress, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
    Set xOutApp = CreateObject("Outlook.Application")
    Set xMailOut = xOutApp.CreateItem(olMailItem)
    For I = 1 To xRg.Rows.Count
        For J = 1 To xRg.Columns.Count
            xEmailBody = xEmailBody & "  " & xRg.Cells(I, J).value
        Next
        xEmailBody = xEmailBody & vbNewLine
    Next
    xEmailBody = "Hi" & vbLf & vbLf & " body of message you want to add" & vbLf & vbLf & xEmailBody & vbNewLine
    With xMailOut
        .Subject = "Test"
        .To = "happy.xuebi@163.com"
        .Body = xEmailBody
        .Display
        '.Send
    End With
    Set xMailOut = Nothing
    Set xOutApp = Nothing
    Application.ScreenUpdating = True
End Sub

Notes:

1). Please change the email body in line xEmailBody = "Hi" & vbLf & vbLf & " body of message you want to add" & vbLf & vbLf & xEmailBody & vbNewLine as you need.

2). Please specify your email recipient and subject .To = happy.xuebi@163.com and .Subject = "test" lines in the code.

5. Press the F5 key to run the code. In the popping up Kutools for Excel dialog box, please select the range you need to paste in the email body, and then click the OK button. See screenshot:

6. Now an email is created with specified recipient, subject, body and selected Excel range, please click the Send button to send this email. See screenshot shown.

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


Related articles:


Recommended Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 71%, 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 82% 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.
    sachin kumr · 11 days ago
    this is pasting as a text. Kindly suggest how to send the table or the same format which is copied from the excel.
  • To post as a guest, your comment is unpublished.
    miguel · 1 months ago
    Code to send automatically after selecting after ok
  • To post as a guest, your comment is unpublished.
    Dhiraj Mahajan · 3 months ago
    Hi
    This code is vary excellent, by using the code i have completed my 90% of my project.
    I have same issue as mentioned by Anirudh that is table formatting. How can i format the table in email.
    Please help me......
    • To post as a guest, your comment is unpublished.
      crystal · 3 months ago
      Good Day,
      The problem can't be solved yet. Sorry for the inconvenience and thank you for your comment.
      • To post as a guest, your comment is unpublished.
        Dhiraj Mahajan · 29 days ago
        Hi, Is there any update on below.......
        • To post as a guest, your comment is unpublished.
          Dhiraj Mahajan · 29 days ago
          Hi, Also I Wanted code for "Filter by Date".
          I am working on project, on that project I wanted to filter the data by the date, actually we have filter/hide the and last 05 days to current date data and we have highlight all other data.
          Please help me to complete this project.
          Your help is very great-full for me.
  • To post as a guest, your comment is unpublished.
    Anirudh · 7 months ago
    This is great. It is working as expected. The only issue is that the format of the table is not maintained in the mail. Can you let me know how do we preserve the format of the table in the mail
  • To post as a guest, your comment is unpublished.
    Michael Ferguson · 8 months ago
    This code is great, but I need to execute with a command button rather than pressing F5 in code view. I'd like my employees to be able to fill out some info, then hit the button and have it copy the range of cells they completed and paste into email. I can get code working for the email button and separately for the copy/paste of the range of cells, but can't seem to combine both functions. Please help!!! Thanks!
    • To post as a guest, your comment is unpublished.
      crystal · 8 months ago
      Hi Michael,
      You just need to create a button (such as a Button (Form Control)) in your worksheet, then assign the macro to the button.